initial setup
@@ -18,76 +18,6 @@ services:
|
||||
- ./mih_nginx/letsencrypt:/etc/letsencrypt
|
||||
networks:
|
||||
- mih-network
|
||||
#============== GITEA ====================================================================
|
||||
mih-gitea:
|
||||
image: gitea/gitea:latest
|
||||
container_name: mih-gitea
|
||||
environment:
|
||||
- USER_UID=1000
|
||||
- USER_GID=1000
|
||||
- GITEA__database__DB_TYPE=mysql
|
||||
- GITEA__database__HOST=mih-gitea-db:3306
|
||||
- GITEA__database__NAME=${GITEA_SQL_DB}
|
||||
- GITEA__database__USER=${GITEA_SQL_USER}
|
||||
- GITEA__database__PASSWD=${GITEA_SQL_PW}
|
||||
restart: always
|
||||
networks:
|
||||
- mih-network
|
||||
volumes:
|
||||
- ./mih_git/gitea:/data
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
- "127.0.0.1:222:22"
|
||||
depends_on:
|
||||
mih-gitea-db:
|
||||
condition: service_healthy
|
||||
mih-gitea-db:
|
||||
image: mysql:8.0
|
||||
container_name: mih-gitea-db
|
||||
restart: always
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=${GITEA_SQL_ROOT_PW}
|
||||
- MYSQL_USER=${GITEA_SQL_USER}
|
||||
- MYSQL_PASSWORD=${GITEA_SQL_PW}
|
||||
- MYSQL_DATABASE=${GITEA_SQL_DB}
|
||||
networks:
|
||||
- mih-network
|
||||
volumes:
|
||||
- ./mih_git/mysql:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
#============== Super Token Auth ====================================================================
|
||||
mih-supertokens:
|
||||
container_name: mih-supertokens
|
||||
image: supertokens/supertokens-mysql:latest
|
||||
depends_on:
|
||||
- mih-db
|
||||
ports:
|
||||
- '127.0.0.1:3567:3567'
|
||||
environment:
|
||||
REFRESH_TOKEN_VALIDITY: '604800'
|
||||
ACCESS_TOKEN_VALIDITY: '86400'
|
||||
PASSWORD_RESET_TOKEN_LIFETIME: '7200000'
|
||||
MYSQL_USER: ${SQL_USER}
|
||||
MYSQL_PASSWORD: ${SQL_USER_PW}
|
||||
MYSQL_HOST: mih-db
|
||||
MYSQL_PORT: 3306
|
||||
MYSQL_DATABASE_NAME: ${SUPERTOKENS_DB}
|
||||
API_KEYS: ${SUPERTOKENS_API_KEY}
|
||||
networks:
|
||||
- mih-network
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: >
|
||||
bash -c 'exec 3<>/dev/tcp/127.0.0.1/3567 && echo -e "GET /hello HTTP/1.1\r\nhost: 127.0.0.1:3567\r\nConnection: close\r\n\r\n" >&3 && cat <&3 | grep "Hello"'
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
#============== MIH WordPress ====================================================================
|
||||
mih-wordpress:
|
||||
container_name: mih-wordpress
|
||||
@@ -117,81 +47,6 @@ services:
|
||||
- ./mih_wp/database:/var/lib/mysql
|
||||
networks:
|
||||
- mih-network
|
||||
#============== MIH-UX Flutter ====================================================================
|
||||
mih-ux:
|
||||
container_name: mih-ux
|
||||
build:
|
||||
context: ./mih_ui
|
||||
ports:
|
||||
- "127.0.0.1:83:83"
|
||||
networks:
|
||||
- mih-network
|
||||
depends_on:
|
||||
- mih-api-hub
|
||||
#============== API Hub ====================================================================
|
||||
mih-api-hub:
|
||||
build:
|
||||
context: ./mih_api_hub
|
||||
target: builder
|
||||
container_name: mih-api-hub
|
||||
ports:
|
||||
- "127.0.0.1:8080:80"
|
||||
volumes:
|
||||
- ./mih_api_hub:/app
|
||||
networks:
|
||||
- mih-network
|
||||
depends_on:
|
||||
- mih-db
|
||||
#============== My SQL DB ====================================================================
|
||||
mih-db:
|
||||
platform: linux/amd64
|
||||
image: mysql:5.7
|
||||
container_name: mih-db
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ${SQL_ROOT_PW}
|
||||
MYSQL_USER: ${SQL_USER}
|
||||
MYSQL_PASSWORD: ${SQL_USER_PW}
|
||||
MYSQL_DATABASE: ${SUPERTOKENS_DB}
|
||||
networks:
|
||||
- mih-network
|
||||
ports:
|
||||
- '127.0.0.1:3306:3306'
|
||||
volumes:
|
||||
- ./mih_db:/var/lib/mysql
|
||||
#============== PHP My Admin ====================================================================
|
||||
# phpmyadmin:
|
||||
# platform: linux/amd64
|
||||
# image: phpmyadmin/phpmyadmin
|
||||
# container_name: MIH-phpmyadmin
|
||||
# environment:
|
||||
# PMA_HOST: mih-db
|
||||
# PMA_PORT: 3306
|
||||
# PMA_ARBITRARY:
|
||||
# networks:
|
||||
# - mih-network
|
||||
# restart: always
|
||||
# ports:
|
||||
# - 8081:80
|
||||
# depends_on:
|
||||
# - mih-db
|
||||
#============== Minio File Storage ====================================================================
|
||||
mih-minio:
|
||||
platform: linux/amd64
|
||||
container_name: mih-minio
|
||||
hostname: mih-minio
|
||||
image: minio/minio
|
||||
ports:
|
||||
- '127.0.0.1:9000:9000'
|
||||
- '127.0.0.1:9001:9001'
|
||||
volumes:
|
||||
- './mih_minio:/data'
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PW}
|
||||
networks:
|
||||
- mih-network
|
||||
command: ["server", "/data", "--console-address", ":9001"]
|
||||
#============== MIH-Monitor Portainer ====================================================================
|
||||
mih-monitor:
|
||||
container_name: mih-monitor
|
||||
@@ -203,49 +58,4 @@ services:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- mih-network
|
||||
#============== MIH-AI Ollama ====================================================================
|
||||
mih-ai:
|
||||
container_name: mih-ai
|
||||
image: ollama/ollama:latest
|
||||
ports:
|
||||
- '127.0.0.1:11434:11434'
|
||||
volumes:
|
||||
- ./mih_ai/ollama/ollama:/root/.ollama
|
||||
pull_policy: always
|
||||
tty: true
|
||||
restart: always
|
||||
environment:
|
||||
- OLLAMA_ORIGINS=*
|
||||
- OLLAMA_KEEP_ALIVE=24h
|
||||
- OLLAMA_HOST=0.0.0.0
|
||||
networks:
|
||||
- mih-network
|
||||
# === Added section for NVIDIA GPU acceleration ===
|
||||
# runtime: nvidia
|
||||
# deploy:
|
||||
# resources:
|
||||
# reservations:
|
||||
# devices:
|
||||
# - driver: nvidia
|
||||
# count: all # or specify a number of GPUs
|
||||
# capabilities: [ gpu ]
|
||||
#============== Firebaase ====================================================================
|
||||
# firebase:
|
||||
# container_name: MIH-firebase-emulator
|
||||
# build:
|
||||
# context: ./Firebase-emulator
|
||||
# environment:
|
||||
# DATA_DIRECTORY: "firebase/data"
|
||||
# FIREBASE_PROJECT: "mzansi-innovation-hub"
|
||||
# ports:
|
||||
# - 8082:8080 # FIRESTORE_PORT
|
||||
# - 5005:5005 # FIRESTORE_WS_PORT
|
||||
# - 4000:4000 # UI_PORT
|
||||
# - 9099:9099 # AUTH_PORT
|
||||
# - 5000:6001 # Hosting
|
||||
# volumes:
|
||||
# - ./Firebase-emulator:/srv/firebase:rw
|
||||
# # - ./cache:/root/.cache/:rw
|
||||
# # - ~/.config/:/root/.config
|
||||
# - ./Firebase-emulator/firebase/data:/srv/firebase/data:rw
|
||||
- mih-network
|
||||
1
mih_ai/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
ollama/ollama
|
||||
BIN
mih_api_hub/.DS_Store
vendored
4
mih_api_hub/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
.env
|
||||
__pycache__/
|
||||
temp*.pdf
|
||||
.DS_Store
|
||||
@@ -1,33 +0,0 @@
|
||||
FROM tiangolo/uvicorn-gunicorn-fastapi:latest AS builder
|
||||
# FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt ./
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
pip --default-timeout=120 install -r requirements.txt
|
||||
|
||||
# COPY . ./app
|
||||
|
||||
# FROM builder as dev-envs
|
||||
|
||||
# RUN <<EOF
|
||||
# apt-get update
|
||||
# apt-get install -y --no-install-recommends git
|
||||
# EOF
|
||||
|
||||
# RUN <<EOF
|
||||
# useradd -s /bin/bash -m vscode
|
||||
# groupadd docker
|
||||
# usermod -aG docker vscode
|
||||
# EOF
|
||||
# # install Docker tools (cli, buildx, compose)
|
||||
# COPY --from=gloursdocker/docker / /
|
||||
|
||||
# FROM python:3.12-slim
|
||||
|
||||
# WORKDIR /app
|
||||
|
||||
# COPY ./requirements.txt ./
|
||||
|
||||
# RUN pip3 install --no-cache-dir -r requirements.txt
|
||||
@@ -1,25 +0,0 @@
|
||||
from minio import Minio
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
minioAccess = os.getenv("MINIO_ACCESS_KEY")
|
||||
minioSecret = os.getenv("MINIO_SECRET_KEY")
|
||||
|
||||
def minioConnect(env):
|
||||
if(env == "Dev"):
|
||||
return Minio(
|
||||
endpoint="mih-minio:9000",
|
||||
# "minio.mzansi-innovation-hub.co.za",
|
||||
access_key=minioAccess,
|
||||
secret_key=minioSecret,
|
||||
secure=False
|
||||
)
|
||||
else:
|
||||
return Minio(
|
||||
# endpoint="mih-minio:9000",
|
||||
endpoint="minio.mzansi-innovation-hub.co.za",
|
||||
access_key=minioAccess,
|
||||
secret_key=minioSecret,
|
||||
secure=True
|
||||
)
|
||||
@@ -1,223 +0,0 @@
|
||||
from typing import Union
|
||||
#import DatabaseConnect
|
||||
import mysql.connector
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
def dbPatientManagerConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
user="root",
|
||||
passwd="root",
|
||||
database="patient_manager"
|
||||
)
|
||||
|
||||
class fileRequest(BaseModel):
|
||||
DocOfficeID: int
|
||||
patientID: int
|
||||
|
||||
# Check if server is up
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return serverRunning()
|
||||
|
||||
# Get Doctors Office By ID
|
||||
@app.get("/docOffices/{docOffic_id}")
|
||||
def read_docOfficeByID(docOffic_id: int):
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM doctor_offices WHERE iddoctor_offices=%s"
|
||||
cursor.execute(query, (docOffic_id,))
|
||||
item = cursor.fetchone()
|
||||
cursor.close()
|
||||
db.close()
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return {"iddoctor_offices": item[0],
|
||||
"office_name": item[1]}
|
||||
|
||||
# Get List of all Doctors Office
|
||||
@app.get("/docOffices/")
|
||||
def read_All_DoctorsOffice():
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM doctor_offices"
|
||||
cursor.execute(query)
|
||||
items = [
|
||||
{
|
||||
"iddoctor_offices": item[0],
|
||||
"office_name": item[1]
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get Patient By ID Number
|
||||
@app.get("/patients/{id_no}")
|
||||
def read_patientByID(id_no: str):
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patients WHERE id_no=%s"
|
||||
cursor.execute(query, (id_no,))
|
||||
item = cursor.fetchone()
|
||||
cursor.close()
|
||||
db.close()
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return {"idpatients": item[0],
|
||||
"id_no": item[1],
|
||||
"first_name": item[2],
|
||||
"last_name": item[3],
|
||||
"email": item[4],
|
||||
"cell_no": item[5],
|
||||
"medical_aid_name": item[6],
|
||||
"medical_aid_no": item[7],
|
||||
"medical_aid_scheme": item[8],
|
||||
"address": item[9],
|
||||
"doc_office_id": item[10]}
|
||||
|
||||
# Get List of all patients
|
||||
@app.get("/patients/")
|
||||
def read_all_patients():
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patients"
|
||||
cursor.execute(query)
|
||||
items = [
|
||||
{
|
||||
"idpatients": item[0],
|
||||
"id_no": item[1],
|
||||
"first_name": item[2],
|
||||
"last_name": item[3],
|
||||
"email": item[4],
|
||||
"cell_no": item[5],
|
||||
"medical_aid_name": item[6],
|
||||
"medical_aid_no": item[7],
|
||||
"medical_aid_scheme": item[8],
|
||||
"address": item[9],
|
||||
"doc_office_id": item[10]
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all patients by Doctors Office
|
||||
@app.get("/docOffice/patients/{docoff_id}")
|
||||
def read_all_patientsby(docoff_id: str):
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patients where doc_office_id=%s"
|
||||
cursor.execute(query, (docoff_id,))
|
||||
items = [
|
||||
{
|
||||
"idpatients": item[0],
|
||||
"id_no": item[1],
|
||||
"first_name": item[2],
|
||||
"last_name": item[3],
|
||||
"email": item[4],
|
||||
"cell_no": item[5],
|
||||
"medical_aid_name": item[6],
|
||||
"medical_aid_no": item[7],
|
||||
"medical_aid_scheme": item[8],
|
||||
"address": item[9],
|
||||
"doc_office_id": item[10]
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all files
|
||||
@app.get("/patients/files/")
|
||||
def read_all_files():
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_files"
|
||||
cursor.execute(query)
|
||||
items = [
|
||||
{
|
||||
"idpatient_files": item[0],
|
||||
"file_path": item[1],
|
||||
"file_name": item[2],
|
||||
"patient_id": item[3],
|
||||
"insert_date": item[4],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all files by patient
|
||||
@app.get("/patients/files/{patientID}")
|
||||
def read_all_files_by_patient(patientID: int):
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_files where patient_id = %s"
|
||||
cursor.execute(query, (patientID,))
|
||||
items = [
|
||||
{
|
||||
"idpatient_files": item[0],
|
||||
"file_path": item[1],
|
||||
"file_name": item[2],
|
||||
"patient_id": item[3],
|
||||
"insert_date": item[4],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all notes
|
||||
@app.get("/patients/notes/")
|
||||
def read_all_notes():
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_notes"
|
||||
cursor.execute(query)
|
||||
items = [
|
||||
{
|
||||
"idpatient_notes": item[0],
|
||||
"note_name": item[1],
|
||||
"note_text": item[2],
|
||||
"insert_date": item[3],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all notes by patient
|
||||
@app.get("/patients/notes/{patientID}")
|
||||
def read_all_patientsby(patientID: int):
|
||||
db = dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_notes where patient_id = %s"
|
||||
cursor.execute(query, (patientID,))
|
||||
items = [
|
||||
{
|
||||
"idpatient_notes": item[0],
|
||||
"note_name": item[1],
|
||||
"note_text": item[2],
|
||||
"insert_date": item[3],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
|
||||
def serverRunning():
|
||||
return {"Status": "Server is Up and Running"}
|
||||
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
from fastapi import FastAPI, Depends, HTTPException
|
||||
from pydantic import BaseModel
|
||||
# from .routers import docOffices, patients, patients_files, patients_notes, users, fileStorage, medicine
|
||||
import routers.docOffices as docOffices
|
||||
import routers.appointments as appointments
|
||||
import routers.patients as patients
|
||||
import routers.patients_files as patients_files
|
||||
import routers.patients_notes as patients_notes
|
||||
import routers.patients_queue as patients_queue
|
||||
import routers.claim_statement_files as claim_statement_files
|
||||
import routers.users as users
|
||||
import routers.notifications as notifications
|
||||
import routers.fileStorage as fileStorage
|
||||
import routers.medicine as medicine
|
||||
import routers.business_user as business_user
|
||||
import routers.business as business
|
||||
import routers.access_request as access_request
|
||||
import routers.patient_access as patient_access
|
||||
import routers.mzansi_wallet as mzansi_wallet
|
||||
import routers.mzansi_directory as mzansi_directory
|
||||
import routers.user_consent as user_consent
|
||||
import routers.icd10_codes as icd10_codes
|
||||
import routers.mine_sweeper_leaderboard as mine_sweeper_leaderboard
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.middleware import Middleware
|
||||
from supertokens_python import get_all_cors_headers
|
||||
from supertokens_python.framework.fastapi import get_middleware
|
||||
|
||||
from supertokens_python import init, InputAppInfo, SupertokensConfig
|
||||
from supertokens_python.recipe import emailpassword, session, dashboard, emailverification
|
||||
|
||||
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.emailverification import EmailVerificationClaim
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
st_api_key = os.getenv("SUPERTOKENS_API_KEY")
|
||||
origins = [
|
||||
"http://localhost",
|
||||
"http://localhost:80",
|
||||
"http://localhost:1995",
|
||||
"http://localhost:8080",
|
||||
"http://MIH-API-Hub:80",
|
||||
"http://MIH-API-Hub",
|
||||
"http://api.mzansi-innovation-hub.co.za",
|
||||
"http://app.mzansi-innovation-hub.co.za",
|
||||
"https://api.mzansi-innovation-hub.co.za",
|
||||
"https://app.mzansi-innovation-hub.co.za",
|
||||
]
|
||||
|
||||
init(
|
||||
app_info=InputAppInfo(
|
||||
app_name="Mzansi Innovation Hub",
|
||||
api_domain="http://localhost:8080/",
|
||||
website_domain="https://app.mzansi-innovation-hub.co.za",
|
||||
api_base_path="/auth",
|
||||
website_base_path="/auth"
|
||||
),
|
||||
supertokens_config=SupertokensConfig(
|
||||
# https://try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
|
||||
connection_uri="http://mih-supertokens:3567/",
|
||||
api_key=st_api_key
|
||||
),
|
||||
framework='fastapi',
|
||||
recipe_list=[
|
||||
# SuperTokens.init(),
|
||||
session.init(), # initializes session features
|
||||
emailpassword.init(),
|
||||
# emailverification.init(mode='REQUIRED'),
|
||||
dashboard.init(admins=[
|
||||
"yasienmeth@gmail.com",
|
||||
],
|
||||
)
|
||||
],
|
||||
mode='wsgi' # use wsgi instead of asgi if you are running using gunicorn
|
||||
)
|
||||
|
||||
app = FastAPI()#middleware=middleware)
|
||||
app.add_middleware(get_middleware())
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
|
||||
allow_headers=["Content-Type"] + get_all_cors_headers()
|
||||
)
|
||||
app.include_router(docOffices.router)
|
||||
app.include_router(patients.router)
|
||||
app.include_router(patients_files.router)
|
||||
app.include_router(patients_notes.router)
|
||||
app.include_router(patients_queue.router)
|
||||
app.include_router(access_request.router)
|
||||
app.include_router(patient_access.router)
|
||||
app.include_router(users.router)
|
||||
app.include_router(fileStorage.router)
|
||||
app.include_router(claim_statement_files.router)
|
||||
app.include_router(medicine.router)
|
||||
app.include_router(business_user.router)
|
||||
app.include_router(business.router)
|
||||
app.include_router(notifications.router)
|
||||
app.include_router(mzansi_wallet.router)
|
||||
app.include_router(mzansi_directory.router)
|
||||
app.include_router(user_consent.router)
|
||||
app.include_router(icd10_codes.router)
|
||||
app.include_router(appointments.router)
|
||||
app.include_router(mine_sweeper_leaderboard.router)
|
||||
|
||||
# Check if server is up
|
||||
@app.get("/", tags=["Server Check"])
|
||||
def check_server():
|
||||
return serverRunning()
|
||||
|
||||
# # Check if server is up
|
||||
# @app.get("/session")
|
||||
# def read_root():
|
||||
# async def like_comment(session: SessionContainer = Depends(verify_session())):
|
||||
# user_id = session.get_user_id()
|
||||
|
||||
# return {"Session id": user_id}
|
||||
|
||||
# @app.post('/get_user_info_api')
|
||||
# async def get_user_info_api(session: SessionContainer = Depends(verify_session())):
|
||||
# user_id = session.get_user_id()
|
||||
|
||||
# thirdparty_user = await get_user_by_id_thirdparty(user_id)
|
||||
# if thirdparty_user is None:
|
||||
# passwordless_user = await get_user_by_id_passwordless(user_id)
|
||||
# if passwordless_user is not None:
|
||||
# print(passwordless_user)
|
||||
# else:
|
||||
# print(thirdparty_user)
|
||||
|
||||
def serverRunning():
|
||||
return {"Status": "Server is Up and Running. whats good in the hood"}
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import mysql.connector
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
dbUser = os.getenv("DB_USER")
|
||||
dbPass = os.getenv("DB_PASSWD")
|
||||
|
||||
def dbPatientManagerConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="patient_manager"
|
||||
)
|
||||
|
||||
def dbAppDataConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="app_data"
|
||||
)
|
||||
|
||||
def dbDataAccessConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="data_access"
|
||||
)
|
||||
|
||||
def dbMzansiWalletConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="mzansi_wallet"
|
||||
)
|
||||
|
||||
def dbMzansiDirectoryConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="mzansi_directory"
|
||||
)
|
||||
|
||||
def dbMzansiCalendarConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
database="mzansi_calendar"
|
||||
)
|
||||
|
||||
def dbAllConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mih-db",
|
||||
user=dbUser,
|
||||
passwd=dbPass,
|
||||
)
|
||||
@@ -1,75 +0,0 @@
|
||||
from sqlalchemy import create_engine
|
||||
import mysql.connector
|
||||
from urllib.parse import quote_plus
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
dbUser = os.getenv("DB_USER")
|
||||
dbPass = os.getenv("DB_PASSWD")
|
||||
dbHost = "mih-db"
|
||||
dbPort = 3306
|
||||
encoded_dbPass = quote_plus(dbPass)
|
||||
base_connect_url = f"mysql+mysqlconnector://{dbUser}:{encoded_dbPass}@{dbHost}:{dbPort}/"
|
||||
|
||||
def dbPatientManagerConnect():
|
||||
return create_engine(base_connect_url+"patient_manager", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="patient_manager"
|
||||
# )
|
||||
|
||||
def dbAppDataConnect():
|
||||
return create_engine(base_connect_url+"app_data", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="app_data"
|
||||
# )
|
||||
|
||||
def dbDataAccessConnect():
|
||||
return create_engine(base_connect_url+"data_access", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="data_access"
|
||||
# )
|
||||
|
||||
def dbMzansiWalletConnect():
|
||||
return create_engine(base_connect_url+"mzansi_wallet", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="mzansi_wallet"
|
||||
# )
|
||||
|
||||
def dbMzansiDirectoryConnect():
|
||||
return create_engine(base_connect_url+"mzansi_directory", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="mzansi_directory"
|
||||
# )
|
||||
|
||||
def dbMzansiCalendarConnect():
|
||||
return create_engine(base_connect_url+"mzansi_calendar", echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# database="mzansi_calendar"
|
||||
# )
|
||||
|
||||
def dbAllConnect():
|
||||
return create_engine(base_connect_url, echo=False, pool_recycle=3600)
|
||||
# return mysql.connector.connect(
|
||||
# host="mih-db",
|
||||
# user=dbUser,
|
||||
# passwd=dbPass,
|
||||
# )
|
||||
@@ -1,121 +0,0 @@
|
||||
from sqlalchemy import DateTime, Column, Integer, String, DECIMAL, text
|
||||
from sqlalchemy.orm import declarative_base
|
||||
Base = declarative_base()
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'users'
|
||||
__table_args__ = {'schema': 'app_data'}
|
||||
idusers = Column(Integer, primary_key=True)
|
||||
email = Column(String(128), nullable=False, unique=True)
|
||||
fname = Column(String(128), nullable=False)
|
||||
lname = Column(String(128), nullable=False)
|
||||
type = Column(String(128), nullable=False)
|
||||
app_id = Column(String(128), nullable=False)
|
||||
username = Column(String(128), nullable=False)
|
||||
pro_pic_path = Column(String(128), nullable=False)
|
||||
purpose = Column(String(256), nullable=False, server_default="")
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<User(idusers={self.idusers}, email='{self.email}', "
|
||||
f"fname='{self.fname}', lname='{self.lname}', type='{self.type}', "
|
||||
f"app_id='{self.app_id}', username='{self.username}', "
|
||||
f"pro_pic_path='{self.pro_pic_path}', purpose='{self.purpose}')>"
|
||||
)
|
||||
|
||||
class Business(Base):
|
||||
__tablename__ = 'business'
|
||||
__table_args__ = {'schema': 'app_data'}
|
||||
idbusiness = Column(Integer, primary_key=True)
|
||||
business_id = Column(String(128), nullable=False, unique=True)
|
||||
Name = Column(String(128))
|
||||
type = Column(String(128))
|
||||
registration_no = Column(String(128))
|
||||
logo_name = Column(String(128))
|
||||
logo_path = Column(String(128))
|
||||
contact_no = Column(String(45))
|
||||
bus_email = Column(String(128))
|
||||
gps_location = Column(String(128))
|
||||
practice_no = Column(String(45))
|
||||
vat_no = Column(String(45))
|
||||
website = Column(String(128))
|
||||
rating = Column(String(45), server_default="''") # Changed to match image default
|
||||
mission_vision = Column(String(256))
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<Business(idbusiness={self.idbusiness}, business_id='{self.business_id}', "
|
||||
f"Name='{self.Name}', type='{self.type}', "
|
||||
f"registration_no='{self.registration_no}', logo_name='{self.logo_name}', "
|
||||
f"logo_path='{self.logo_path}', contact_no='{self.contact_no}', "
|
||||
f"bus_email='{self.bus_email}', gps_location='{self.gps_location}', "
|
||||
f"practice_no='{self.practice_no}', vat_no='{self.vat_no}', "
|
||||
f"website='{self.website}', rating='{self.rating}', "
|
||||
f"mission_vision='{self.mission_vision}')>"
|
||||
)
|
||||
|
||||
class BusinessRating(Base):
|
||||
__tablename__ = 'business_ratings'
|
||||
__table_args__ = {'schema': 'mzansi_directory'}
|
||||
idbusiness_ratings = Column(Integer, primary_key=True)
|
||||
app_id = Column(String(128), nullable=False, server_default="")
|
||||
business_id = Column(String(128), nullable=False, server_default="")
|
||||
rating_title = Column(String(128), nullable=False, server_default="")
|
||||
rating_description = Column(String(256), nullable=False, server_default="")
|
||||
rating_score = Column(String(45), nullable=False, server_default="")
|
||||
date_time = Column(DateTime, nullable=True)
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<BusinessRating(idbusiness_ratings={self.idbusiness_ratings}, app_id='{self.app_id}', "
|
||||
f"business_id='{self.business_id}', rating_title='{self.rating_title}', rating_description='{self.rating_description}', "
|
||||
f"rating_score='{self.rating_score}', date_time='{self.date_time}')>"
|
||||
)
|
||||
class BookmarkedBusiness(Base):
|
||||
__tablename__ = 'bookmarked_businesses'
|
||||
__table_args__ = {'schema': 'mzansi_directory'}
|
||||
idbookmarked_businesses = Column(Integer, primary_key=True)
|
||||
app_id = Column(String(128), nullable=False, server_default="")
|
||||
business_id = Column(String(128), nullable=False, server_default="")
|
||||
created_date = Column(DateTime, nullable=True)
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<BusinessRating(idbookmarked_businesses={self.idbookmarked_businesses}, app_id='{self.app_id}', "
|
||||
f"business_id='{self.business_id}', created_date='{self.created_date}')>"
|
||||
)
|
||||
|
||||
|
||||
class UserConsent(Base):
|
||||
__tablename__ = 'user_consent'
|
||||
__table_args__ = {'schema': 'app_data'}
|
||||
iduser_consent = Column(Integer, primary_key=True)
|
||||
app_id = Column(String(128), nullable=False,server_default=text("''"))
|
||||
privacy_policy_accepted = Column(DateTime, nullable=True)
|
||||
terms_of_services_accepted = Column(DateTime, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<UserConsent(iduser_consent={self.iduser_consent}, "
|
||||
f"app_id='{self.app_id}', "
|
||||
f"privacy_policy_accepted='{self.privacy_policy_accepted}', "
|
||||
f"terms_of_services_accepted='{self.terms_of_services_accepted}')>"
|
||||
)
|
||||
|
||||
class MineSweeperLeaderboard(Base):
|
||||
__tablename__ = 'player_score'
|
||||
__table_args__ = {'schema': 'minesweeper_leaderboard'}
|
||||
idplayer_score = Column(Integer, primary_key=True)
|
||||
app_id = Column(String(128), nullable=False,server_default=text("''"))
|
||||
difficulty = Column(String(45), nullable=False,server_default=text("''"))
|
||||
game_time = Column(String(45), nullable=False,server_default=text("''"))
|
||||
game_score = Column(DECIMAL(45), nullable=False)
|
||||
played_date = Column(DateTime, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f"<MineSweeperLeaderboard(idplayer_score={self.idplayer_score}, "
|
||||
f"app_id='{self.app_id}', "
|
||||
f"difficulty='{self.difficulty}', "
|
||||
f"game_time='{self.game_time}', "
|
||||
f"game_score='{self.game_score}' "
|
||||
f"played_date='{self.played_date}')>"
|
||||
)
|
||||
@@ -1,13 +0,0 @@
|
||||
fastapi
|
||||
uvicorn
|
||||
sqlalchemy
|
||||
mysql-connector-python
|
||||
minio
|
||||
reportlab
|
||||
requests
|
||||
watchfiles
|
||||
python-multipart
|
||||
python-dotenv
|
||||
xlrd
|
||||
supertokens-python==0.24.0
|
||||
sniffio
|
||||
@@ -1,130 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
from datetime import date
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class accessUpdateRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
date_time: str
|
||||
access: str
|
||||
|
||||
class accessExtensionRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
date_time: str
|
||||
revoke_date: str
|
||||
|
||||
# class queueInsertRequest(BaseModel):
|
||||
# business_id: str
|
||||
# app_id: str
|
||||
# date: str
|
||||
# time: str
|
||||
# access: str
|
||||
|
||||
@router.get("/access-requests/{app_id}", tags=["Access Requests"])
|
||||
async def read_all_access_request_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT patient_queue.idpatient_queue, patient_queue.business_id, "
|
||||
query += "patient_queue.app_id, patient_queue.date_time, patient_queue.access, patient_queue.revoke_date, "
|
||||
query += "business.Name, business.type, business.logo_path, business.contact_no "
|
||||
query += "from patient_manager.patient_queue "
|
||||
query += "inner join app_data.business "
|
||||
query += "on patient_queue.business_id = business.business_id "
|
||||
query += "where app_id = %s ORDER BY date_time DESC"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idpatient_queue": item[0],
|
||||
"business_id": item[1],
|
||||
"app_id": item[2],
|
||||
"date_time": item[3],
|
||||
"access": item[4],
|
||||
"revoke_date": item[5],
|
||||
"Name": item[6],
|
||||
"type": item[7],
|
||||
"logo_path": item[8],
|
||||
"contact_no": item[9],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
@router.put("/access-requests/update/", tags=["Access Requests"])
|
||||
async def Update_access_request_approcal(itemRequest : accessUpdateRequest): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update patient_queue "
|
||||
query += "set access=%s"
|
||||
query += "where business_id=%s "
|
||||
query += "and app_id=%s "
|
||||
query += "and date_time=%s "
|
||||
userData = (itemRequest.access,
|
||||
itemRequest.business_id,
|
||||
itemRequest.app_id,
|
||||
itemRequest.date_time)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
@router.put("/access-requests/extension/", tags=["Access Requests"])
|
||||
async def Update_access_request_approcal(itemRequest : accessExtensionRequest): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update patient_queue "
|
||||
query += "set access=%s, revoke_date=%s"
|
||||
query += "where business_id=%s "
|
||||
query += "and app_id=%s "
|
||||
query += "and date_time=%s "
|
||||
userData = ("pending",
|
||||
itemRequest.revoke_date,
|
||||
itemRequest.business_id,
|
||||
itemRequest.app_id,
|
||||
itemRequest.date_time)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# # Get List of all files
|
||||
# @router.get("/files/patients/", tags="patients_files")
|
||||
# async def read_all_files(session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM patient_files"
|
||||
# cursor.execute(query)
|
||||
# items = [
|
||||
# {
|
||||
# "idpatient_files": item[0],
|
||||
# "file_path": item[1],
|
||||
# "file_name": item[2],
|
||||
# "patient_id": item[3],
|
||||
# "insert_date": item[4],
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
@@ -1,157 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
from datetime import datetime, timedelta, date
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class appointmentInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
business_id: str
|
||||
title: str
|
||||
description: str
|
||||
date: str
|
||||
time: str
|
||||
|
||||
class appointmentUpdateRequest(BaseModel):
|
||||
idappointments: int
|
||||
title: str
|
||||
description: str
|
||||
date: str
|
||||
time: str
|
||||
|
||||
class appointmentDeleteRequest(BaseModel):
|
||||
idappointments: int
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.get("/appointments/business/{business_id}", tags=["Appointments"])
|
||||
async def read_all_appointments_by_business_id(business_id: str, date: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbMzansiCalendarConnect()
|
||||
requestDate = datetime.strptime(date, '%Y-%m-%d').date()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT appointments.idappointments, appointments.app_id, "
|
||||
query += "appointments.business_id, appointments.date_time, "
|
||||
query += "appointments.title, appointments.description "
|
||||
query += "from mzansi_calendar.appointments "
|
||||
query = query + "where appointments.business_id = %s and date_time like '" + str(requestDate) + "%' "
|
||||
query += "ORDER BY date_time ASC"
|
||||
cursor.execute(query, (business_id,))
|
||||
items = [
|
||||
{
|
||||
"idappointments": item[0],
|
||||
"app_id": item[1],
|
||||
"business_id": item[2],
|
||||
"date_time": item[3],
|
||||
"title": item[4],
|
||||
"description": item[5],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.get("/appointments/personal/{app_id}", tags=["Appointments"])
|
||||
async def read_all_appointments_by_business_id(app_id: str, date: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbMzansiCalendarConnect()
|
||||
requestDate = datetime.strptime(date, '%Y-%m-%d').date()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT appointments.idappointments, appointments.app_id, "
|
||||
query += "appointments.business_id, appointments.date_time, "
|
||||
query += "appointments.title, appointments.description "
|
||||
query += "from mzansi_calendar.appointments "
|
||||
query = query + "where appointments.app_id = %s and date_time like '" + str(requestDate) + "%' "
|
||||
query += "ORDER BY date_time ASC"
|
||||
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idappointments": item[0],
|
||||
"app_id": item[1],
|
||||
"business_id": item[2],
|
||||
"date_time": item[3],
|
||||
"title": item[4],
|
||||
"description": item[5],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Insert Patient note into table
|
||||
@router.post("/appointment/insert/", tags=["Appointments"], status_code=201)
|
||||
async def insert_appointment(itemRequest : appointmentInsertRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
date_time = itemRequest.date + " " + itemRequest.time + ":00"
|
||||
db = mih_database.dbConnection.dbMzansiCalendarConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into appointments "
|
||||
query += "(app_id, business_id, title, description, date_time) "
|
||||
query += "values (%s, %s, %s, %s, %s)"
|
||||
notetData = (itemRequest.app_id,
|
||||
itemRequest.business_id,
|
||||
itemRequest.title,
|
||||
itemRequest.description,
|
||||
date_time,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, notetData)
|
||||
except Exception as error:
|
||||
#raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created file Record"}
|
||||
|
||||
# Update Patient on table
|
||||
@router.put("/appointment/update/", tags=["Appointments"])
|
||||
async def Update_appointment(itemRequest : appointmentUpdateRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
|
||||
date_time = itemRequest.date + " " + itemRequest.time + ":00"
|
||||
|
||||
db = mih_database.dbConnection.dbMzansiCalendarConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update appointments "
|
||||
query += "set date_time=%s, title=%s, description=%s "
|
||||
query += "where idappointments=%s"
|
||||
patientData = (date_time,
|
||||
itemRequest.title,
|
||||
itemRequest.description,
|
||||
itemRequest.idappointments)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# Update Patient on table
|
||||
@router.delete("/appointment/delete/", tags=["Appointments"])
|
||||
async def Delete_appointment(itemRequest : appointmentDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbMzansiCalendarConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from appointments "
|
||||
query += "where idappointments=%s"
|
||||
try:
|
||||
cursor.execute(query, (str(itemRequest.idappointments),))
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Delete Appointment")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully deleted Appointment"}
|
||||
|
||||
@@ -1,385 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
import mih_database.mihDbConnections
|
||||
from mih_database.mihDbObjects import User, Business, BusinessRating, BookmarkedBusiness
|
||||
from sqlalchemy import desc, or_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql import func
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
import uuid
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# class userRequest(BaseModel):
|
||||
# email: str
|
||||
# DocOfficeID: int
|
||||
|
||||
class businessInsertRequest(BaseModel):
|
||||
Name: str
|
||||
type: str
|
||||
registration_no: str
|
||||
logo_name: str
|
||||
logo_path: str
|
||||
contact_no: str
|
||||
bus_email: str
|
||||
gps_location: str
|
||||
practice_no: str
|
||||
vat_no: str
|
||||
website: str
|
||||
rating: str
|
||||
mission_vision: str
|
||||
|
||||
class businessUpdateRequest(BaseModel):
|
||||
business_id: str
|
||||
Name: str
|
||||
type: str
|
||||
registration_no: str
|
||||
logo_name: str
|
||||
logo_path: str
|
||||
contact_no: str
|
||||
bus_email: str
|
||||
gps_location: str
|
||||
practice_no: str
|
||||
vat_no: str
|
||||
|
||||
class businessUpdateRequestV2(BaseModel):
|
||||
business_id: str
|
||||
Name: str
|
||||
type: str
|
||||
registration_no: str
|
||||
logo_name: str
|
||||
logo_path: str
|
||||
contact_no: str
|
||||
bus_email: str
|
||||
gps_location: str
|
||||
practice_no: str
|
||||
vat_no: str
|
||||
website: str
|
||||
rating: str
|
||||
mission_vision: str
|
||||
|
||||
@router.get("/business/count/", tags=["MIH Business"])
|
||||
async def read_business_by_business_id(): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(func.count(Business.business_id)).scalar()
|
||||
response_data = {"count": queryResults}
|
||||
return response_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/business/types/", tags=["MIH Business"])
|
||||
async def read_business_by_business_id(session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(Business.type).distinct().order_by(Business.type).all()
|
||||
response_data = [{"type": t[0]} for t in queryResults]
|
||||
return response_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/business/search/{type}/{search}", tags=["MIH Business"])
|
||||
async def read_all_businesses(search: str, type: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(Business)
|
||||
type_term_with_wildcards = ""
|
||||
if type != "All":
|
||||
type_term_with_wildcards = f"%{type.lower()}%"
|
||||
queryResults = queryResults.filter(
|
||||
Business.type.ilike(type_term_with_wildcards)
|
||||
)
|
||||
search_term_with_wildcards = ""
|
||||
if search != "All":
|
||||
search_term_with_wildcards = f"%{search.lower()}%"
|
||||
queryResults = queryResults.filter(
|
||||
or_(
|
||||
Business.Name.ilike(search_term_with_wildcards),
|
||||
Business.bus_email.ilike(search_term_with_wildcards),
|
||||
Business.mission_vision.ilike(search_term_with_wildcards),
|
||||
)
|
||||
)
|
||||
queryResults = queryResults.all()
|
||||
response_data = []
|
||||
for business in queryResults:
|
||||
response_data.append({
|
||||
"business_id": business.business_id,
|
||||
"Name": business.Name,
|
||||
"type": business.type,
|
||||
"registration_no": business.registration_no,
|
||||
"logo_name": business.logo_name,
|
||||
"logo_path": business.logo_path,
|
||||
"contact_no": business.contact_no,
|
||||
"bus_email": business.bus_email,
|
||||
"app_id": "",
|
||||
"gps_location": business.gps_location,
|
||||
"practice_no": business.practice_no,
|
||||
"vat_no": business.vat_no,
|
||||
"website": business.website,
|
||||
"rating": business.rating,
|
||||
"mission_vision": business.mission_vision,
|
||||
})
|
||||
|
||||
return response_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
# db = mih_database.dbConnection.dbAppDataConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT business.business_id, business.Name, business.type, business.registration_no, "
|
||||
# query += "business.logo_name, business.logo_path, business.contact_no, business.bus_email, "
|
||||
# query += "business.gps_location, "
|
||||
# query += "practice_no, vat_no, "
|
||||
# query += "website, rating, mission_vision "
|
||||
# query += "FROM business "
|
||||
# query += "WHERE LOWER(business.Name) LIKE %s OR LOWER(business.type) LIKE %s "
|
||||
# query += "OR LOWER(business.bus_email) LIKE %s OR LOWER(business.mission_vision) LIKE %s"
|
||||
# search_term = f"%{search.lower()}%" # Add wildcards and lowercase
|
||||
# cursor.execute(query, (search_term, search_term, search_term, search_term))
|
||||
# items = [
|
||||
# {
|
||||
# "business_id": item[0],
|
||||
# "Name": item[1],
|
||||
# "type": item[2],
|
||||
# "registration_no": item[3],
|
||||
# "logo_name": item[4],
|
||||
# "logo_path": item[5],
|
||||
# "contact_no": item[6],
|
||||
# "bus_email": item[7],
|
||||
# "app_id": "",
|
||||
# "gps_location": item[8],
|
||||
# "practice_no": item[9],
|
||||
# "vat_no": item[10],
|
||||
# "website": item[11],
|
||||
# "rating": item[12],
|
||||
# "mission_vision": item[13],
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/business/business_id/{business_id}", tags=["MIH Business"])
|
||||
async def read_business_by_business_id(business_id: str): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(Business).\
|
||||
filter(
|
||||
Business.business_id == business_id,
|
||||
).first()
|
||||
if queryResults:
|
||||
return {
|
||||
"business_id": queryResults.business_id,
|
||||
"Name": queryResults.Name,
|
||||
"type": queryResults.type,
|
||||
"registration_no": queryResults.registration_no,
|
||||
"logo_name": queryResults.logo_name,
|
||||
"logo_path": queryResults.logo_path,
|
||||
"contact_no": queryResults.contact_no,
|
||||
"bus_email": queryResults.bus_email,
|
||||
"app_id": "",
|
||||
"gps_location": queryResults.gps_location,
|
||||
"practice_no": queryResults.practice_no,
|
||||
"vat_no": queryResults.vat_no,
|
||||
"website": queryResults.website,
|
||||
"rating": queryResults.rating,
|
||||
"mission_vision": queryResults.mission_vision,
|
||||
}
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Business not found for the given business_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/business/app_id/{app_id}", tags=["MIH Business"])
|
||||
async def read_business_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT business.business_id, business.Name, business.type, business.registration_no, "
|
||||
query += "business.logo_name, business.logo_path, business.contact_no, business.bus_email, "
|
||||
query += "business_users.app_id, business.gps_location, "
|
||||
query += "practice_no, vat_no, "
|
||||
query += "website, rating, mission_vision "
|
||||
query += "FROM business "
|
||||
query += "inner join business_users "
|
||||
query += "on business.business_id=business_users.business_id "
|
||||
query += "where business_users.app_id = %s"
|
||||
try:
|
||||
cursor.execute(query, (app_id,))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to pull records")
|
||||
items = [
|
||||
{
|
||||
"business_id": item[0],
|
||||
"Name": item[1],
|
||||
"type": item[2],
|
||||
"registration_no": item[3],
|
||||
"logo_name": item[4],
|
||||
"logo_path": item[5],
|
||||
"contact_no": item[6],
|
||||
"bus_email": item[7],
|
||||
"app_id": item[8],
|
||||
"gps_location": item[9],
|
||||
"practice_no": item[10],
|
||||
"vat_no": item[11],
|
||||
"website": item[12],
|
||||
"rating": item[13],
|
||||
"mission_vision": item[14],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
if(len(items)!= 0):
|
||||
return items[0]
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="No record found")
|
||||
|
||||
# Insert Patient into table
|
||||
@router.post("/business/insert/", tags=["MIH Business"], status_code=201)
|
||||
async def insert_business_details(itemRequest : businessInsertRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into business "
|
||||
query += "(business_id, Name, type, registration_no, logo_name, logo_path, contact_no, bus_email, gps_location, practice_no, vat_no, website, rating, mission_vision) "
|
||||
query += "values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
uuidString = str(uuid.uuid1())
|
||||
userData = (uuidString,
|
||||
itemRequest.Name,
|
||||
itemRequest.type,
|
||||
itemRequest.registration_no,
|
||||
itemRequest.logo_name,
|
||||
itemRequest.logo_path,
|
||||
itemRequest.contact_no,
|
||||
itemRequest.bus_email,
|
||||
itemRequest.gps_location,
|
||||
itemRequest.practice_no,
|
||||
itemRequest.vat_no,
|
||||
itemRequest.website,
|
||||
itemRequest.rating,
|
||||
itemRequest.mission_vision,
|
||||
)
|
||||
try:
|
||||
print(query)
|
||||
print(userData)
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
# return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"business_id": uuidString}
|
||||
|
||||
@router.put("/business/update/", tags=["MIH Business"])
|
||||
async def Update_Business_details(itemRequest : businessUpdateRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
# print(itemRequest.gps_location)
|
||||
cursor = db.cursor()
|
||||
query = "update business "
|
||||
query += "set Name=%s, type=%s, registration_no=%s, logo_name=%s, logo_path=%s, contact_no=%s, bus_email=%s, gps_location=%s, practice_no=%s, vat_no=%s "
|
||||
query += "where business_id=%s"
|
||||
userData = (itemRequest.Name,
|
||||
itemRequest.type,
|
||||
itemRequest.registration_no,
|
||||
itemRequest.logo_name.replace(" ", "-"),
|
||||
itemRequest.logo_path.replace(" ", "-"),
|
||||
itemRequest.contact_no,
|
||||
itemRequest.bus_email,
|
||||
itemRequest.gps_location,
|
||||
itemRequest.practice_no,
|
||||
itemRequest.vat_no,
|
||||
itemRequest.business_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
@router.put("/business/update/v2/", tags=["MIH Business"])
|
||||
async def Update_Business_details(itemRequest : businessUpdateRequestV2, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
# print(itemRequest.gps_location)
|
||||
cursor = db.cursor()
|
||||
query = "update business "
|
||||
query += "set Name=%s, type=%s, registration_no=%s, logo_name=%s, logo_path=%s, contact_no=%s, bus_email=%s, gps_location=%s, practice_no=%s, vat_no=%s, website=%s, rating=%s, mission_vision=%s "
|
||||
query += "where business_id=%s"
|
||||
userData = (itemRequest.Name,
|
||||
itemRequest.type,
|
||||
itemRequest.registration_no,
|
||||
itemRequest.logo_name.replace(" ", "-"),
|
||||
itemRequest.logo_path.replace(" ", "-"),
|
||||
itemRequest.contact_no,
|
||||
itemRequest.bus_email,
|
||||
itemRequest.gps_location,
|
||||
itemRequest.practice_no,
|
||||
itemRequest.vat_no,
|
||||
itemRequest.website,
|
||||
itemRequest.rating,
|
||||
itemRequest.mission_vision,
|
||||
itemRequest.business_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
@@ -1,252 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# class userRequest(BaseModel):
|
||||
# email: str
|
||||
# DocOfficeID: int
|
||||
|
||||
class businessUserInsertRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
signature: str
|
||||
sig_path: str
|
||||
title: str
|
||||
access: str
|
||||
|
||||
class BusinessUserUpdateRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
signature: str
|
||||
sig_path: str
|
||||
title: str
|
||||
access: str
|
||||
|
||||
class EmployeeUpdateRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
title: str
|
||||
access: str
|
||||
|
||||
class employeeDeleteRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/business-user/{app_id}", tags=["MIH Business_User"])
|
||||
async def read_business_users_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM business_users where app_id = %s"
|
||||
try:
|
||||
cursor.execute(query, (app_id,))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed - " + error)
|
||||
items = [
|
||||
{
|
||||
"idbusiness_users": item[0],
|
||||
"business_id": item[1],
|
||||
"app_id": item[2],
|
||||
"signature": item[3],
|
||||
"sig_path": item[4],
|
||||
"title": item[5],
|
||||
"access": item[6],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
if(len(items)!= 0):
|
||||
return items[0]
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="No record found")
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/business-user/employees/{business_id}", tags=["MIH Business_User"])
|
||||
async def read_business_users_by_business_id(business_id: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = ""
|
||||
query += "SELECT business_users.business_id, business_users.app_id, business_users.title, business_users.access, "
|
||||
query += "users.fname, users.lname, users.email, users.username "
|
||||
query += "FROM business_users "
|
||||
query += "inner join users on business_users.app_id = users.app_id "
|
||||
query += "where business_id = %s "
|
||||
try:
|
||||
cursor.execute(query, (business_id,))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed - " + error)
|
||||
items = [
|
||||
{
|
||||
"business_id": item[0],
|
||||
"app_id": item[1],
|
||||
"title": item[2],
|
||||
"access": item[3],
|
||||
"fname": item[4],
|
||||
"lname": item[5],
|
||||
"email": item[6],
|
||||
"username": item[7],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
if(len(items)!= 0):
|
||||
return items
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="No record found")
|
||||
|
||||
# Insert Patient into table
|
||||
@router.post("/business-user/insert/", tags=["MIH Business_User"], status_code=201)
|
||||
async def insert_User_details(itemRequest : businessUserInsertRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
checkQuery = "SELECT * FROM business_users where app_id = %s"
|
||||
try:
|
||||
cursor.execute(checkQuery, (itemRequest.app_id,))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed - " + error)
|
||||
items = [
|
||||
{
|
||||
"idbusiness_users": item[0],
|
||||
"business_id": item[1],
|
||||
"app_id": item[2],
|
||||
"signature": item[3],
|
||||
"sig_path": item[4],
|
||||
"title": item[5],
|
||||
"access": item[6],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
#print(f"checkQuery: {len(items)}")
|
||||
if(len(items) <1):
|
||||
createQuery = "insert into business_users "
|
||||
createQuery += "(business_id, app_id, signature, sig_path, title, access) "
|
||||
createQuery += "values (%s, %s, %s, %s, %s, %s)"
|
||||
userData1 = (itemRequest.business_id,
|
||||
itemRequest.app_id,
|
||||
itemRequest.signature,
|
||||
itemRequest.sig_path,
|
||||
itemRequest.title,
|
||||
itemRequest.access)
|
||||
try:
|
||||
cursor.execute(createQuery, userData1)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
#return {"message": "Failed to Create Record"}
|
||||
else:
|
||||
updateQuery = "update business_users "
|
||||
updateQuery += "set business_id=%s, title=%s, access=%s "
|
||||
updateQuery += "where app_id=%s"
|
||||
userData2 = (itemRequest.business_id,
|
||||
itemRequest.title,
|
||||
itemRequest.access,
|
||||
itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(updateQuery, userData2)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
|
||||
updateTypeQuery = "update users "
|
||||
updateTypeQuery += "set type='business' "
|
||||
updateTypeQuery += "where app_id=%s"
|
||||
userData2 = (
|
||||
itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(updateTypeQuery, userData2)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
# Update User on table
|
||||
@router.put("/business-user/update/", tags=["MIH Business_User"])
|
||||
async def Update_User_details(itemRequest : BusinessUserUpdateRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update business_users "
|
||||
query += "set signature=%s,sig_path=%s, title=%s, access=%s"
|
||||
query += "where app_id=%s and business_id=%s"
|
||||
userData = (itemRequest.signature,
|
||||
itemRequest.sig_path,
|
||||
itemRequest.title,
|
||||
itemRequest.access,
|
||||
itemRequest.app_id,
|
||||
itemRequest.business_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# Update User on table
|
||||
@router.put("/business-user/employees/update/", tags=["MIH Business_User"])
|
||||
async def Update_User_details(itemRequest : EmployeeUpdateRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update business_users "
|
||||
query += "set title=%s, access=%s"
|
||||
query += "where app_id=%s and business_id=%s"
|
||||
userData = (
|
||||
itemRequest.title,
|
||||
itemRequest.access,
|
||||
itemRequest.app_id,
|
||||
itemRequest.business_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# Delete Patient note on table
|
||||
@router.delete("/business-user/employees/delete/", tags=["MIH Business_User"])
|
||||
async def Delete_Patient_note(itemRequest : employeeDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
# today = date.today()
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from business_users "
|
||||
query += "where business_id=%s "
|
||||
query += "and app_id=%s"
|
||||
# notetData = (itemRequest.idpatient_notes)
|
||||
try:
|
||||
cursor.execute(query, (itemRequest.business_id,
|
||||
itemRequest.app_id,))
|
||||
except Exception as error:
|
||||
#raise HTTPException(status_code=404, detail="Failed to Delete Record")
|
||||
return {"query": query, "message": error}
|
||||
|
||||
updateTypeQuery = "update users "
|
||||
updateTypeQuery += "set type='personal' "
|
||||
updateTypeQuery += "where app_id=%s"
|
||||
userData2 = (
|
||||
itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(updateTypeQuery, userData2)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully deleted Record"}
|
||||
@@ -1,112 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
from datetime import date
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class claimStatementDeleteRequest(BaseModel):
|
||||
idclaim_statement_file: int
|
||||
|
||||
class claimStatementInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
business_id: str
|
||||
file_path: str
|
||||
file_name: str
|
||||
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.get("/files/claim-statement/patient/{app_id}", tags=["Claim Statement Files"])
|
||||
async def read_all_claim_statement_files_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM claim_statement_file where app_id = %s ORDER BY insert_date DESC"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idclaim_statement_file": item[0],
|
||||
"app_id": item[1],
|
||||
"business_id": item[2],
|
||||
"insert_date": item[3],
|
||||
"file_path": item[4],
|
||||
"file_name": item[5],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.get("/files/claim-statement/business/{business_id}", tags=["Claim Statement Files"])
|
||||
async def read_all_claim_statement_files_by_business_id(business_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM claim_statement_file where business_id = %s ORDER BY insert_date DESC"
|
||||
cursor.execute(query, (business_id,))
|
||||
items = [
|
||||
{
|
||||
"idclaim_statement_file": item[0],
|
||||
"app_id": item[1],
|
||||
"business_id": item[2],
|
||||
"insert_date": item[3],
|
||||
"file_path": item[4],
|
||||
"file_name": item[5],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Delete Patient note on table
|
||||
@router.delete("/files/claim-statement/delete/", tags=["Claim Statement Files"])
|
||||
async def Delete_Patient_File(itemRequest : claimStatementDeleteRequest, session: SessionContainer = Depends(verify_session())): #session: SessionContainer = Depends(verify_session())
|
||||
# today = date.today()
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from claim_statement_file "
|
||||
query += "where idclaim_statement_file=%s"
|
||||
# notetData = (itemRequest.idpatient_notes)
|
||||
try:
|
||||
cursor.execute(query, (str(itemRequest.idclaim_statement_file),))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Delete Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully deleted Record"}
|
||||
|
||||
# Insert Patient note into table
|
||||
@router.post("/files/claim-statement/insert/", tags=["Claim Statement Files"], status_code=201)
|
||||
async def insert_Patient_Files(itemRequest : claimStatementInsertRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
today = date.today()
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into claim_statement_file "
|
||||
query += "(app_id, business_id, file_path, file_name, insert_date) "
|
||||
query += "values (%s, %s, %s, %s, %s)"
|
||||
notetData = (
|
||||
itemRequest.app_id,
|
||||
itemRequest.business_id,
|
||||
itemRequest.file_path,
|
||||
itemRequest.file_name,
|
||||
today,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, notetData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
# return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created file Record"}
|
||||
@@ -1,64 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# Get Doctors Office By ID
|
||||
@router.get("/docOffices/{docOffic_id}", tags=["Doctor Office"])
|
||||
async def read_docOffice_By_ID(docOffic_id: int, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM doctor_offices WHERE iddoctor_offices=%s"
|
||||
cursor.execute(query, (docOffic_id,))
|
||||
item = cursor.fetchone()
|
||||
cursor.close()
|
||||
db.close()
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return {"iddoctor_offices": item[0],
|
||||
"office_name": item[1]}
|
||||
|
||||
# Get Doctors Office By user
|
||||
@router.get("/docOffices/user/{user}", tags=["Doctor Office"])
|
||||
async def read_docOffice_By_ID(user: str, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM users WHERE email=%s"
|
||||
cursor.execute(query, (user,))
|
||||
item = cursor.fetchone()
|
||||
cursor.close()
|
||||
db.close()
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return {
|
||||
"idUser": item[0],
|
||||
"UserName": item[1],
|
||||
"docOffice_id": item[2],
|
||||
"fname": item[3],
|
||||
"lname": item[4],
|
||||
"title": item[5],
|
||||
}
|
||||
|
||||
# Get List of all Doctors Office
|
||||
@router.get("/docOffices/", tags=["Doctor Office"])
|
||||
async def read_All_Doctors_Office(session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM doctor_offices"
|
||||
cursor.execute(query)
|
||||
items = [
|
||||
{
|
||||
"iddoctor_offices": item[0],
|
||||
"office_name": item[1]
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
@@ -1,574 +0,0 @@
|
||||
from textwrap import wrap
|
||||
import io
|
||||
from datetime import datetime, date
|
||||
from typing import List
|
||||
import requests
|
||||
|
||||
from fastapi import APIRouter, HTTPException, File, UploadFile, Form
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from minio import Minio
|
||||
import Minio_Storage
|
||||
|
||||
from reportlab.pdfgen import canvas
|
||||
from reportlab.lib.pagesizes import A4
|
||||
from reportlab.lib.utils import ImageReader
|
||||
from reportlab.platypus import SimpleDocTemplate
|
||||
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
import Minio_Storage.minioConnection
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class minioPullRequest(BaseModel):
|
||||
file_path: str
|
||||
|
||||
class minioDeleteRequest(BaseModel):
|
||||
file_path: str
|
||||
env: str
|
||||
|
||||
class medCertUploud(BaseModel):
|
||||
app_id: str
|
||||
env: str
|
||||
patient_full_name: str
|
||||
fileName: str
|
||||
id_no: str
|
||||
docfname: str
|
||||
busName: str
|
||||
busAddr: str
|
||||
busNo: str
|
||||
busEmail: str
|
||||
startDate: str
|
||||
endDate: str
|
||||
returnDate: str
|
||||
logo_path: str
|
||||
sig_path: str
|
||||
|
||||
class perscription(BaseModel):
|
||||
name: str
|
||||
unit: str
|
||||
form: str
|
||||
fullForm: str
|
||||
quantity: str
|
||||
dosage: str
|
||||
times: str
|
||||
days: str
|
||||
repeats: str
|
||||
|
||||
class perscriptionList(BaseModel):
|
||||
app_id: str
|
||||
env: str
|
||||
patient_full_name: str
|
||||
fileName: str
|
||||
id_no: str
|
||||
docfname: str
|
||||
busName: str
|
||||
busAddr: str
|
||||
busNo: str
|
||||
busEmail: str
|
||||
logo_path: str
|
||||
sig_path: str
|
||||
data: List[perscription]
|
||||
|
||||
class claimStatementUploud(BaseModel):
|
||||
document_type: str
|
||||
patient_app_id: str
|
||||
env: str
|
||||
patient_full_name: str
|
||||
fileName: str
|
||||
patient_id_no: str
|
||||
has_med_aid: str
|
||||
med_aid_no: str
|
||||
med_aid_code: str
|
||||
med_aid_name: str
|
||||
med_aid_scheme: str
|
||||
busName: str
|
||||
busAddr: str
|
||||
busNo: str
|
||||
busEmail: str
|
||||
provider_name: str
|
||||
practice_no: str
|
||||
vat_no: str
|
||||
service_date: str
|
||||
service_desc: str
|
||||
service_desc_option: str
|
||||
procedure_name: str
|
||||
# procedure_date: str
|
||||
procedure_additional_info: str
|
||||
icd10_code: str
|
||||
amount: str
|
||||
pre_auth_no: str
|
||||
logo_path: str
|
||||
sig_path: str
|
||||
|
||||
@router.get("/minio/pull/file/{env}/{app_id}/{folder}/{file_name}", tags=["Minio"])
|
||||
async def pull_File_from_user(app_id: str, folder: str, file_name: str, env: str): #, session: SessionContainer = Depends(verify_session())
|
||||
path = app_id + "/" + folder + "/" + file_name
|
||||
print(path)
|
||||
try:
|
||||
# print(f"env: {env}")
|
||||
# uploudFile(app_id, file.filename, extension[1], content)
|
||||
|
||||
client = Minio_Storage.minioConnection.minioConnect(env)
|
||||
# buckets = client.list_buckets()
|
||||
# print("Connected to MinIO successfully!")
|
||||
# print("Available buckets:", [bucket.name for bucket in buckets])
|
||||
miniourl = client.presigned_get_object(
|
||||
bucket_name="mih",
|
||||
object_name=path,
|
||||
expires=timedelta(minutes=60)
|
||||
)
|
||||
print("Generated presigned URL:", miniourl)
|
||||
# if(env == "Dev"):
|
||||
# miniourl.replace("minio", "localhost")
|
||||
# temp = minioResponse.data#.encode('utf-8').strip()
|
||||
# print(temp)
|
||||
# print("=======================================================================")
|
||||
# temp = temp.decode('utf-8')
|
||||
#print(miniourl)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=f"MinIO connection failed: {str(error)}")
|
||||
# return {"message": error}
|
||||
if(env == "Dev"):
|
||||
return {
|
||||
# 10.0.2.2
|
||||
"minioURL": f"http://10.0.2.2:9000/mih/{app_id}/{folder}/{file_name}",#"http://localhost:9000/mih/{app_id}/{folder}/{file_name}",
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"minioURL": miniourl,
|
||||
}
|
||||
|
||||
@router.post("/minio/upload/file/", tags=["Minio"])
|
||||
async def upload_File_to_user(file: UploadFile = File(...), app_id: str= Form(...), env: str= Form(...), folder: str= Form(...), session: SessionContainer = Depends(verify_session())):
|
||||
extension = file.filename.split(".")
|
||||
content = file.file
|
||||
try:
|
||||
uploudFile(app_id, env, folder, file.filename.replace(" ", "-"), extension[1], content)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=str(error))
|
||||
return {"message": f"Successfully Uploaded {file.filename}"}
|
||||
|
||||
# return {
|
||||
# "app_id": app_id,
|
||||
# "file name": file.filename,
|
||||
# "extension": extension[0],
|
||||
# "file contents": file.file.read(),
|
||||
# }
|
||||
|
||||
@router.delete("/minio/delete/file/", tags=["Minio"])
|
||||
async def delete_File_of_user(requestItem: minioDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
path = requestItem.file_path
|
||||
try:
|
||||
# uploudFile(app_id, file.filename, extension[1], content)
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
|
||||
minioError = client.remove_object(
|
||||
bucket_name="mih",
|
||||
object_name=path
|
||||
)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=minioError)
|
||||
# return {"message": error}
|
||||
return {"message": "Successfully deleted File"}
|
||||
# return {
|
||||
# "app_id": app_id,
|
||||
# "file name": file.filename,
|
||||
# "extension": extension[0],
|
||||
# "file contents": file.file.read(),
|
||||
# }
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.post("/minio/generate/med-cert/", tags=["Minio"])
|
||||
async def upload_med_cert_to_user(requestItem: medCertUploud, session: SessionContainer = Depends(verify_session())):
|
||||
uploudMedCert(requestItem)
|
||||
return {"message": "Successfully Generated File"}
|
||||
|
||||
@router.post("/minio/generate/perscription/", tags=["Minio"])
|
||||
async def upload_perscription_to_user(requestItem: perscriptionList, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
uploudPerscription(requestItem)
|
||||
return {"message": "Successfully Generated File"}
|
||||
|
||||
@router.post("/minio/generate/claim-statement/", tags=["Minio"])
|
||||
async def upload_perscription_to_user(requestItem: claimStatementUploud, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
uploudClaimStatement(requestItem)
|
||||
return {"message": "Successfully Generated File"}
|
||||
|
||||
def uploudFile(app_id, env, folder, fileName, extension, content):
|
||||
client = Minio_Storage.minioConnection.minioConnect(env)
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fname = app_id + "/" + folder + "/" + fileName
|
||||
client.put_object(
|
||||
bucket_name="mih",
|
||||
object_name=fname,
|
||||
data=content,
|
||||
length=-1,
|
||||
part_size=10*1024*1024,
|
||||
content_type=f"application/{extension}")
|
||||
|
||||
def uploudMedCert(requestItem: medCertUploud):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
generateMedCertPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fileName = f"{requestItem.app_id}/patient_files/{requestItem.fileName}"
|
||||
client.fput_object("mih", fileName, "temp-med-cert.pdf")
|
||||
|
||||
def generateMedCertPDF(requestItem: medCertUploud):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
new_logo_path = requestItem.logo_path.replace(" ","-")
|
||||
new_sig_path = requestItem.sig_path.replace(" ","-")
|
||||
minioLogo = client.get_object("mih", new_logo_path).read()
|
||||
imageLogo = ImageReader(io.BytesIO(minioLogo))
|
||||
minioSig = client.get_object("mih", new_sig_path).read()
|
||||
imageSig = ImageReader(io.BytesIO(minioSig))
|
||||
w,h = A4
|
||||
today = datetime.today().strftime('%d-%m-%Y')
|
||||
myCanvas = canvas.Canvas("temp-med-cert.pdf", pagesize=A4)
|
||||
|
||||
#Business Logo
|
||||
myCanvas.drawImage(imageLogo, 50, h - 125,100,100, mask='auto')
|
||||
|
||||
#Business Details
|
||||
myCanvas.setFont('Helvetica-Bold', 10)
|
||||
myCanvas.drawRightString(w - 50,h - 40, f"Name: {requestItem.busName}")
|
||||
myCanvas.drawRightString(w - 50,h - 55, f"Address: {requestItem.busAddr}")
|
||||
myCanvas.drawRightString(w - 50,h - 70, f"Contact No.: {requestItem.busNo}")
|
||||
myCanvas.drawRightString(w - 50,h - 85, f"Email: {requestItem.busEmail}")
|
||||
myCanvas.line(50,h-150,w-50,h-150)
|
||||
#Todays Date
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
issueDate = str(today)
|
||||
myCanvas.drawRightString(w - 50,h - 180,issueDate)
|
||||
|
||||
#Title
|
||||
myCanvas.setFont('Helvetica-Bold', 20)
|
||||
myCanvas.drawString(w-375, h - 200, "Medical Certificate")
|
||||
|
||||
#Body
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
body = ""
|
||||
body += "This is to certify that " + requestItem.patient_full_name.upper() + " (" + requestItem.id_no+ ") was seen by " + requestItem.docfname.upper() + " on " + requestItem.startDate + "."
|
||||
body += "\nHe/She is unfit to attend work/school from " + requestItem.startDate + " up to and including " + requestItem.endDate + "."
|
||||
body += "\nHe/She will return on " + requestItem.returnDate + "."
|
||||
|
||||
y = 250
|
||||
for line in wrap(body, 90):
|
||||
myCanvas.drawString(50, h-y, line)
|
||||
y += 30
|
||||
# myCanvas.drawString(50, h-250,line1)
|
||||
# myCanvas.drawString(50, h-280,line2)
|
||||
# myCanvas.drawString(50, h-310,line3)
|
||||
|
||||
#Signature
|
||||
myCanvas.drawImage(imageSig, 50, h - 690,100,100)
|
||||
myCanvas.line(50,h-700,200,h-700)
|
||||
myCanvas.drawString(50, h-720, requestItem.docfname.upper())
|
||||
|
||||
#QR Verification
|
||||
qrText = requestItem.patient_full_name.upper() + " booked off from " + requestItem.startDate + " to " + requestItem.endDate + " by " + requestItem.docfname.upper() + ".\nPowered by Mzansi Innovation Hub."
|
||||
qrText = qrText.replace(" ","+")
|
||||
|
||||
url = f"https://api.qrserver.com/v1/create-qr-code/?data={qrText}&size=100x100"
|
||||
response = requests.get(url)
|
||||
image = ImageReader(io.BytesIO(response.content))
|
||||
myCanvas.drawImage(image,w-150, h-700,100,100)
|
||||
|
||||
myCanvas.setFont('Helvetica-Bold', 15)
|
||||
myCanvas.drawString(w-150,h-720,"Scan to verify")
|
||||
|
||||
myCanvas.save()
|
||||
|
||||
def uploudPerscription(requestItem: perscriptionList):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
generatePerscriptionPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fileName = f"{requestItem.app_id}/patient_files/{requestItem.fileName}"
|
||||
client.fput_object("mih", fileName, "temp-perscription.pdf")
|
||||
|
||||
def generatePerscriptionPDF(requestItem: perscriptionList):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
new_logo_path = requestItem.logo_path.replace(" ","-")
|
||||
new_sig_path = requestItem.sig_path.replace(" ","-")
|
||||
minioLogo = client.get_object("mih", new_logo_path).read()
|
||||
imageLogo = ImageReader(io.BytesIO(minioLogo))
|
||||
minioSig = client.get_object("mih", new_sig_path).read()
|
||||
imageSig = ImageReader(io.BytesIO(minioSig))
|
||||
w,h = A4
|
||||
|
||||
|
||||
myCanvas = canvas.Canvas("temp-perscription.pdf", pagesize=A4)
|
||||
|
||||
#Business Logo
|
||||
myCanvas.drawImage(imageLogo, 50, h - 125,100,100, mask='auto')
|
||||
|
||||
#Business Details
|
||||
myCanvas.setFont('Helvetica-Bold', 10)
|
||||
myCanvas.drawRightString(w - 50,h - 40, f"Name: {requestItem.busName}")
|
||||
myCanvas.drawRightString(w - 50,h - 55, f"Address: {requestItem.busAddr}")
|
||||
myCanvas.drawRightString(w - 50,h - 70, f"Contact No.: {requestItem.busNo}")
|
||||
myCanvas.drawRightString(w - 50,h - 85, f"Email: {requestItem.busEmail}")
|
||||
myCanvas.line(50,h-150,w-50,h-150)
|
||||
#Todays Date
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
today = datetime.today()
|
||||
issueDate = today.strftime('%d-%m-%Y')
|
||||
myCanvas.drawRightString(w - 50,h - 180,issueDate)
|
||||
|
||||
#Title
|
||||
myCanvas.setFont('Helvetica-Bold', 20)
|
||||
myCanvas.drawString(w-375, h - 200, "Perscription")
|
||||
|
||||
#Body
|
||||
myCanvas.setFont('Helvetica-Bold', 12)
|
||||
myCanvas.drawString(50, h-250, f"Patient: {requestItem.patient_full_name}")
|
||||
myCanvas.drawString(50, h-270, f"Patient ID: {requestItem.id_no}")
|
||||
|
||||
#boday headings
|
||||
myCanvas.drawString(50, h-300, "Description")
|
||||
myCanvas.drawRightString(w - 50, h-300, "Repeat(s)")
|
||||
myCanvas.drawRightString(w - 150, h-300, "Quantity")
|
||||
myCanvas.line(50,h-310,w-50,h-310)
|
||||
|
||||
myCanvas.setStrokeColorRGB(0.749, 0.749, 0.749)
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
y = 330
|
||||
i = 0
|
||||
for persc in requestItem.data:
|
||||
description1 = f"{persc.name} - {persc.form}"
|
||||
description2 = f"{persc.dosage} {persc.fullForm}, {persc.times} time(s) daily, for {persc.days} day(s)"
|
||||
quant = f"{persc.quantity}"
|
||||
reps = f"{persc.repeats}"
|
||||
|
||||
myCanvas.drawString(50, h-y, f"{i+1}.")
|
||||
myCanvas.drawString(60, h-y, description1)
|
||||
myCanvas.drawRightString(w-75, h-y, reps)
|
||||
myCanvas.drawRightString(w-175, h-y, quant)
|
||||
y+=15
|
||||
myCanvas.drawString(60, h-y, description2)
|
||||
if(i<len(requestItem.data)-1):
|
||||
y+=10
|
||||
myCanvas.line(50,h-y,w-50,h-y)
|
||||
y += 20
|
||||
i+=1
|
||||
myCanvas.setStrokeColorRGB(0,0,0)
|
||||
myCanvas.line(50,h-y-10,w-50,h-y-10)
|
||||
|
||||
|
||||
#Signature
|
||||
y=750
|
||||
myCanvas.drawImage(imageSig, 50, h-y,100,100)
|
||||
myCanvas.line(50,h-y-10,200,h-y-10)
|
||||
myCanvas.drawString(50, h-y-30, requestItem.docfname.upper())
|
||||
|
||||
#QR Verification
|
||||
qrText = f"Perscription generated on {issueDate} by {requestItem.docfname} for {requestItem.patient_full_name}.\nPowered by Mzansi Innovation Hub."
|
||||
qrText = qrText.replace(" ","+")
|
||||
|
||||
url = f"https://api.qrserver.com/v1/create-qr-code/?data={qrText}&size=100x100"
|
||||
response = requests.get(url)
|
||||
image = ImageReader(io.BytesIO(response.content))
|
||||
myCanvas.drawImage(image,w-150, h-y-10,100,100)
|
||||
|
||||
myCanvas.setFont('Helvetica-Bold', 15)
|
||||
myCanvas.drawString(w-150,h-y-30,"Scan to verify")
|
||||
|
||||
myCanvas.save()
|
||||
|
||||
def uploudClaimStatement(requestItem: claimStatementUploud):
|
||||
try:
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
print("connected")
|
||||
except Exception:
|
||||
print("error")
|
||||
|
||||
generateClaimStatementPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket(bucket_name="mih")
|
||||
else:
|
||||
print("Bucket already exists")
|
||||
fileName = f"{requestItem.patient_app_id}/claims-statements/{requestItem.fileName}"
|
||||
client.fput_object("mih", fileName, "temp-claim-statement.pdf")
|
||||
|
||||
def generateClaimStatementPDF(requestItem: claimStatementUploud):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
# print("buckets: " + client.list_buckets)
|
||||
new_logo_path = requestItem.logo_path.replace(" ","-")
|
||||
new_sig_path = requestItem.sig_path.replace(" ","-")
|
||||
print("Path Logo: " + new_logo_path)
|
||||
minioLogo = client.get_object("mih", new_logo_path).read()
|
||||
imageLogo = ImageReader(io.BytesIO(minioLogo))
|
||||
minioSig = client.get_object("mih", new_sig_path).read()
|
||||
imageSig = ImageReader(io.BytesIO(minioSig))
|
||||
w,h = A4
|
||||
|
||||
|
||||
myCanvas = canvas.Canvas("temp-claim-statement.pdf", pagesize=A4)
|
||||
|
||||
#Business Logo
|
||||
myCanvas.drawImage(imageLogo, 50, h - 125,100,100, mask='auto')
|
||||
|
||||
#Business Details
|
||||
myCanvas.setFont('Helvetica-Bold', 10)
|
||||
myCanvas.drawRightString(w - 50,h - 40, f"Name: {requestItem.busName}")
|
||||
myCanvas.drawRightString(w - 50,h - 55, f"Address: {requestItem.busAddr}")
|
||||
myCanvas.drawRightString(w - 50,h - 70, f"Practice No.: {requestItem.practice_no}")
|
||||
myCanvas.drawRightString(w - 50,h - 85, f"Contact No.: {requestItem.busNo}")
|
||||
myCanvas.drawRightString(w - 50,h - 100, f"Email: {requestItem.busEmail}")
|
||||
myCanvas.line(50,h-150,w-50,h-150)
|
||||
#Todays Date
|
||||
myCanvas.setFont('Helvetica-Bold', 12)
|
||||
today = datetime.today()
|
||||
issueDate = today.strftime('%d-%m-%Y')
|
||||
myCanvas.drawRightString(w - 50,h - 180,f"{issueDate}")
|
||||
|
||||
#Title
|
||||
myCanvas.setFont('Helvetica-Bold', 20)
|
||||
myCanvas.drawString(w-340, h - 200, requestItem.document_type)
|
||||
|
||||
#Body
|
||||
# Patient Details
|
||||
myCanvas.setFont('Helvetica-Bold', 14)
|
||||
myCanvas.drawString(50, h-230, "Patient Details")
|
||||
myCanvas.line(50,h-235,w-50,h-235)
|
||||
|
||||
medAidNo = ""
|
||||
medAidCode = ""
|
||||
medAidNameAndScheme = ""
|
||||
if(requestItem.has_med_aid == "Yes"):
|
||||
medAidNo = requestItem.med_aid_no
|
||||
medAidCode = requestItem.med_aid_code
|
||||
medAidNameAndScheme = f"{requestItem.med_aid_name} - {requestItem.med_aid_scheme}"
|
||||
else:
|
||||
medAidNo = "n/a"
|
||||
medAidCode = "n/a"
|
||||
medAidNameAndScheme = "n/a"
|
||||
preAuthNo = requestItem.pre_auth_no
|
||||
if(preAuthNo == ""):
|
||||
preAuthNo = "n/a"
|
||||
# category
|
||||
myCanvas.setFont('Helvetica-Bold', 12)
|
||||
myCanvas.drawString(50, h-250, f"Patient Name:")
|
||||
myCanvas.drawString(50, h-265, f"Patient ID:")
|
||||
myCanvas.drawString(50, h-280, f"Medical Aid No.:")
|
||||
myCanvas.drawString(50, h-295, f"Medical Aid Code:")
|
||||
myCanvas.drawString(50, h-310, f"Medical Aid Scheme:")
|
||||
myCanvas.drawString(50, h-325, f"Pre-Authorisation No:")
|
||||
# content
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
myCanvas.drawString(225, h-250, f"{requestItem.patient_full_name}")
|
||||
myCanvas.drawString(225, h-265, f"{requestItem.patient_id_no}")
|
||||
myCanvas.drawString(225, h-280, f"{medAidNo}")
|
||||
myCanvas.drawString(225, h-295, f"{medAidCode}")
|
||||
myCanvas.drawString(225, h-310, f"{medAidNameAndScheme}")
|
||||
myCanvas.drawString(225, h-325, f"{preAuthNo}")
|
||||
#===============================================================================
|
||||
# Provide Details
|
||||
myCanvas.setFont('Helvetica-Bold', 14)
|
||||
myCanvas.drawString(50, h-355, "Provider Details")
|
||||
myCanvas.line(50,h-360,w-50,h-360)
|
||||
|
||||
myCanvas.setFont('Helvetica-Bold', 12)
|
||||
myCanvas.drawString(50, h-375, f"Practice Name:")
|
||||
myCanvas.drawString(50, h-390, f"Practice No.:")
|
||||
myCanvas.drawString(50, h-405, f"Vat No.:")
|
||||
myCanvas.drawString(50, h-420, f"Provider Name:")
|
||||
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
myCanvas.drawString(225, h-375, f"{requestItem.busName}")
|
||||
myCanvas.drawString(225, h-390, f"{requestItem.practice_no}")
|
||||
myCanvas.drawString(225, h-405, f"{requestItem.vat_no}")
|
||||
myCanvas.drawString(225, h-420, f"{requestItem.provider_name}")
|
||||
|
||||
#===============================================================================
|
||||
# Service Details
|
||||
myCanvas.setFont('Helvetica-Bold', 14)
|
||||
myCanvas.drawString(50, h-450, "Service Details")
|
||||
# myCanvas.drawRightString(w - 50, h-300, "Repeat(s)")
|
||||
myCanvas.drawRightString(w - 70, h-450, "Amount")
|
||||
myCanvas.line(50,h-455,w-50,h-455)
|
||||
|
||||
myCanvas.setFont('Helvetica-Bold', 12)
|
||||
myCanvas.drawString(50, h-470, f"Service Type:")
|
||||
myCanvas.drawString(50, h-485, f"Service Date:")
|
||||
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
myCanvas.drawString(225, h-470, f"{requestItem.service_desc}")
|
||||
displayAmount = ""
|
||||
if("." in requestItem.amount or "," in requestItem.amount):
|
||||
displayAmount = requestItem.amount.replace(",",".")
|
||||
else:
|
||||
displayAmount = requestItem.amount + ".00"
|
||||
myCanvas.drawRightString(w - 80, h-470, displayAmount)
|
||||
myCanvas.drawString(225, h-485, f"{requestItem.service_date}")
|
||||
y = 0
|
||||
if(requestItem.service_desc == "Precedure"):
|
||||
myCanvas.setFont('Helvetica-Bold', 12)
|
||||
myCanvas.drawString(50, h-500, f"Procedure Name:")
|
||||
myCanvas.drawString(50, h-515, f"Additional Info:")
|
||||
myCanvas.drawString(50, h-530, f"ICD-10 Code & Description:")
|
||||
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
myCanvas.drawString(225, h-500, f"{requestItem.procedure_name}")
|
||||
myCanvas.drawString(225, h-515, f"{requestItem.procedure_additional_info}")
|
||||
y = 530
|
||||
for line in wrap(requestItem.icd10_code, 45):
|
||||
myCanvas.drawString(225, h-y, f"{line}")
|
||||
y+=15
|
||||
myCanvas.line(50,h-y,w-50,h-y)
|
||||
else:
|
||||
myCanvas.setFont('Helvetica-Bold', 12)
|
||||
myCanvas.drawString(50, h-500, f"Service Description:")
|
||||
myCanvas.drawString(50, h-515, f"ICD-10 Code & Description:")
|
||||
|
||||
myCanvas.setFont('Helvetica', 12)
|
||||
myCanvas.drawString(225, h-500, f"{requestItem.service_desc_option}")
|
||||
y = 515
|
||||
for line in wrap(requestItem.icd10_code, 45):
|
||||
myCanvas.drawString(225, h-y, f"{line}")
|
||||
y+=15
|
||||
# myCanvas.drawString(225, h-515, f"{requestItem.icd10_code}")
|
||||
myCanvas.line(50,h-y,w-50,h-y)
|
||||
#===============================================================================
|
||||
|
||||
#Signature
|
||||
y=750
|
||||
myCanvas.drawImage(imageSig, 50, h-y,100,100)
|
||||
myCanvas.line(50,h-y-10,200,h-y-10)
|
||||
myCanvas.drawString(50, h-y-30, requestItem.provider_name.upper())
|
||||
|
||||
#QR Verification
|
||||
qrText = f"{requestItem.document_type} generated on {issueDate} by {requestItem.busName} for {requestItem.patient_full_name}.\nPowered by Mzansi Innovation Hub."
|
||||
qrText = qrText.replace(" ","+")
|
||||
|
||||
url = f"https://api.qrserver.com/v1/create-qr-code/?data={qrText}&size=100x100"
|
||||
response = requests.get(url)
|
||||
image = ImageReader(io.BytesIO(response.content))
|
||||
myCanvas.drawImage(image,w-150, h-y-10,100,100)
|
||||
|
||||
myCanvas.setFont('Helvetica-Bold', 15)
|
||||
myCanvas.drawString(w-150,h-y-30,"Scan to verify")
|
||||
|
||||
myCanvas.save()
|
||||
@@ -1,48 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
import os
|
||||
import xlrd
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
#get all medicines
|
||||
@router.get("/icd10-codes/all", tags=["ICD10 Code"])
|
||||
async def read_all_icd10_codes(session: SessionContainer = Depends(verify_session())):
|
||||
return getICD10CodesData("")
|
||||
|
||||
#get all medicines by search
|
||||
@router.get("/icd10-codes/{search}", tags=["ICD10 Code"])
|
||||
async def read_icd10_codes_search(search: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
return getICD10CodesData(search)
|
||||
|
||||
def getICD10CodesData(search: str):
|
||||
path = os.getcwd()
|
||||
#print(path)
|
||||
#parentDir = os.path.abspath(os.path.join(path, os.pardir))
|
||||
filePath = os.path.join(path, "ICD10_Codes", "ICD-10_MIT_2021_Excel_16-March_2021.xls")
|
||||
print(f'========================= %s ===============================',filePath)
|
||||
book = xlrd.open_workbook_xls(filePath)
|
||||
sh = book.sheet_by_index(0)
|
||||
codeList = []
|
||||
for rx in range(1,sh.nrows):
|
||||
if(str(sh.cell_value(rx, 7)).strip() != ""
|
||||
and search.lower() in str(sh.cell_value(rx, 7)).strip().lower()
|
||||
or search.lower() in str(sh.cell_value(rx, 8)).strip().lower()):
|
||||
codeList.append({
|
||||
"icd10": str(sh.cell_value(rx, 7)).strip(),
|
||||
"description": str(sh.cell_value(rx, 8)).strip(),
|
||||
})
|
||||
seen = set()
|
||||
codeList_noDuplicates = []
|
||||
for d in codeList:
|
||||
t = tuple(d.items())
|
||||
#print(t[0][1])
|
||||
if t not in seen:
|
||||
seen.add(t)
|
||||
codeList_noDuplicates.append(d)
|
||||
return sorted(codeList_noDuplicates, key=lambda d: d['icd10']) #qsort(medlist)
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
import os
|
||||
import xlrd
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
#get all medicines
|
||||
@router.get("/users/medicine/all", tags=["Medicine"])
|
||||
async def read_all_medicine(session: SessionContainer = Depends(verify_session())):
|
||||
return getMedicineData("")
|
||||
|
||||
#get all medicines by search
|
||||
@router.get("/users/medicine/{medSearch}", tags=["Medicine"])
|
||||
async def read_medicineby_search(medSearch: str, session: SessionContainer = Depends(verify_session())):
|
||||
return getMedicineData(medSearch)
|
||||
|
||||
def getMedicineData(medsearch: str):
|
||||
path = os.getcwd()
|
||||
#print(path)
|
||||
#parentDir = os.path.abspath(os.path.join(path, os.pardir))
|
||||
filePath = os.path.join(path, "medicines", "Database-Of-Medicine-Prices-9-July-2024.xls")
|
||||
book = xlrd.open_workbook_xls(filePath)
|
||||
sh = book.sheet_by_index(0)
|
||||
medlist = []
|
||||
for rx in range(1,sh.nrows):
|
||||
if(str(sh.cell_value(rx, 6)).strip() != "" and
|
||||
medsearch.lower() in str(sh.cell_value(rx, 6)).strip().lower()):
|
||||
medlist.append({
|
||||
"name": str(sh.cell_value(rx, 6)).strip(),
|
||||
"unit": str(sh.cell_value(rx, 9)).strip(),
|
||||
"dosage form": str(sh.cell_value(rx, 10)).strip(),
|
||||
})
|
||||
seen = set()
|
||||
medlist_noDuplicates = []
|
||||
for d in medlist:
|
||||
t = tuple(d.items())
|
||||
#print(t[0][1])
|
||||
if t not in seen:
|
||||
seen.add(t)
|
||||
medlist_noDuplicates.append(d)
|
||||
return sorted(medlist_noDuplicates, key=lambda d: d['name']) #qsort(medlist)
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from pydantic import BaseModel
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
import mih_database
|
||||
import mih_database.mihDbConnections
|
||||
from mih_database.mihDbObjects import MineSweeperLeaderboard, User
|
||||
from sqlalchemy import and_, func, literal_column
|
||||
from sqlalchemy.orm import Session, aliased
|
||||
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
||||
from datetime import datetime
|
||||
from sqlalchemy.sql.expression import select
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class playerScoreInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
difficulty: str
|
||||
game_time: str
|
||||
game_score: float
|
||||
played_date: datetime
|
||||
|
||||
# get top 20 scores
|
||||
@router.get("/minesweeper/leaderboard/top20/{difficulty}", tags=["Minesweeper"])
|
||||
async def get_user_consent(difficulty: str, session: SessionContainer = Depends(verify_session())):#session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
max_score_subquery = (
|
||||
dbSession.query(
|
||||
MineSweeperLeaderboard.app_id,
|
||||
func.max(MineSweeperLeaderboard.game_score).label('max_score')
|
||||
)
|
||||
.filter(MineSweeperLeaderboard.difficulty == difficulty)
|
||||
.group_by(MineSweeperLeaderboard.app_id)
|
||||
.subquery('max_scores')
|
||||
)
|
||||
queryResults = (
|
||||
dbSession.query(MineSweeperLeaderboard, User)
|
||||
.join(User, User.app_id == MineSweeperLeaderboard.app_id)
|
||||
.join(
|
||||
max_score_subquery,
|
||||
and_(
|
||||
MineSweeperLeaderboard.app_id == max_score_subquery.c.app_id,
|
||||
MineSweeperLeaderboard.game_score == max_score_subquery.c.max_score
|
||||
)
|
||||
)
|
||||
.filter(MineSweeperLeaderboard.difficulty == difficulty)
|
||||
.order_by(MineSweeperLeaderboard.game_score.desc())
|
||||
.limit(20)
|
||||
.all()
|
||||
)
|
||||
leaderboardData = []
|
||||
if queryResults:
|
||||
for playerScore, user in queryResults:
|
||||
leaderboardData.append({
|
||||
"app_id": playerScore.app_id,
|
||||
"username": user.username,
|
||||
"proPicUrl":user.pro_pic_path,
|
||||
"difficulty":playerScore.difficulty,
|
||||
"game_time":playerScore.game_time,
|
||||
"game_score":playerScore.game_score,
|
||||
"played_date":playerScore.played_date,
|
||||
})
|
||||
return leaderboardData
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No Score available for user."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.get("/minesweeper/leaderboard/top_score/{difficulty}/{app_id}", tags=["Minesweeper"])
|
||||
async def get_user_consent(app_id: str,
|
||||
difficulty: str,
|
||||
session: SessionContainer = Depends(verify_session())):#session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults =(dbSession.query(MineSweeperLeaderboard, User)
|
||||
.join(User, User.app_id == MineSweeperLeaderboard.app_id)
|
||||
.filter(
|
||||
and_(
|
||||
MineSweeperLeaderboard.app_id == app_id,
|
||||
MineSweeperLeaderboard.difficulty == difficulty
|
||||
)
|
||||
)
|
||||
.order_by(MineSweeperLeaderboard.game_score.desc())
|
||||
.all())
|
||||
if not queryResults:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No scores found for this user and difficulty level."
|
||||
)
|
||||
leaderboard_data = []
|
||||
for player_score, user in queryResults:
|
||||
score_data = {
|
||||
"app_id": player_score.app_id,
|
||||
"username": user.username,
|
||||
"proPicUrl": user.pro_pic_path,
|
||||
"difficulty": player_score.difficulty,
|
||||
"game_time": player_score.game_time,
|
||||
"game_score": player_score.game_score,
|
||||
"played_date": player_score.played_date,
|
||||
}
|
||||
leaderboard_data.append(score_data)
|
||||
return leaderboard_data
|
||||
except HTTPException as http_exc:
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.post("/minesweeper/leaderboard/player_score/insert/",
|
||||
tags=["Minesweeper"],
|
||||
status_code=status.HTTP_201_CREATED)
|
||||
async def insert_user_consent(itemRequest: playerScoreInsertRequest,
|
||||
session: SessionContainer = Depends(verify_session())):#session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
newPlayerScore = MineSweeperLeaderboard(
|
||||
app_id = itemRequest.app_id,
|
||||
difficulty = itemRequest.difficulty,
|
||||
game_time = itemRequest.game_time,
|
||||
game_score = itemRequest.game_score,
|
||||
played_date = itemRequest.played_date,
|
||||
)
|
||||
dbSession.add(newPlayerScore)
|
||||
dbSession.commit()
|
||||
dbSession.refresh(newPlayerScore)
|
||||
return {"message": "Successfully Created Player Score Record"}
|
||||
except IntegrityError as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT, # 409 Conflict is often suitable for constraint errors
|
||||
detail=f"Data integrity error: The provided data violates a database constraint. Details: {e.orig}"
|
||||
) from e
|
||||
except SQLAlchemyError as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"A database error occurred during insertion. Details: {e.orig}"
|
||||
) from e
|
||||
except Exception as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"An unexpected error occurred: {e}"
|
||||
) from e
|
||||
finally:
|
||||
dbSession.close()
|
||||
@@ -1,459 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.orm import Session
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
import mih_database.mihDbConnections
|
||||
from mih_database.mihDbObjects import User, Business, BusinessRating, BookmarkedBusiness
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# class BusinessRatingUserGet(BaseModel):
|
||||
# app_id: str
|
||||
# business_id: str
|
||||
|
||||
class BusinessRatingInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
business_id: str
|
||||
rating_title: str
|
||||
rating_description: str
|
||||
rating_score: str
|
||||
current_rating: str
|
||||
|
||||
class BusinessRatingDeleteRequest(BaseModel):
|
||||
idbusiness_ratings: int
|
||||
business_id: str
|
||||
rating_score: str
|
||||
current_rating: str
|
||||
|
||||
class BusinessRatingUpdateRequest(BaseModel):
|
||||
idbusiness_ratings: int
|
||||
business_id: str
|
||||
rating_title: str
|
||||
rating_description: str
|
||||
rating_new_score: str
|
||||
rating_old_score: str
|
||||
current_rating: str
|
||||
|
||||
class BookmarkedBusinessInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
business_id: str
|
||||
|
||||
class BookmarkedBusinessDeleteRequest(BaseModel):
|
||||
idbookmarked_businesses: int
|
||||
|
||||
########################################################
|
||||
# Business Ratings #
|
||||
########################################################
|
||||
|
||||
@router.get("/mzansi-directory/business-ratings/user/{app_id}/{business_id}", tags=["Mzansi Directory"])
|
||||
async def read_all_ratings_by_business_id(app_id: str,business_id: str, session: SessionContainer = Depends(verify_session())): # , session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(BusinessRating, User).\
|
||||
join(User, BusinessRating.app_id == User.app_id).\
|
||||
filter(
|
||||
BusinessRating.business_id == business_id,
|
||||
BusinessRating.app_id == app_id
|
||||
).first()
|
||||
if queryResults:
|
||||
rating_obj, user_obj = queryResults
|
||||
# Return a single dictionary
|
||||
return {
|
||||
"idbusiness_ratings": rating_obj.idbusiness_ratings,
|
||||
"app_id": rating_obj.app_id,
|
||||
"business_id": rating_obj.business_id,
|
||||
"rating_title": rating_obj.rating_title,
|
||||
"rating_description": rating_obj.rating_description,
|
||||
"rating_score": rating_obj.rating_score,
|
||||
"date_time": rating_obj.date_time,
|
||||
"reviewer": user_obj.username,
|
||||
}
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Business rating not found for the given app_id and business_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.get("/mzansi-directory/business-ratings/all/{business_id}", tags=["Mzansi Directory"])
|
||||
async def read_all_ratings_by_business_id(business_id: str): # , session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(BusinessRating, User).\
|
||||
join(User, BusinessRating.app_id == User.app_id).\
|
||||
filter(
|
||||
BusinessRating.business_id == business_id,
|
||||
).order_by(
|
||||
desc(BusinessRating.date_time)
|
||||
).all()
|
||||
response_data = []
|
||||
for rating_obj, user_obj in queryResults:
|
||||
response_data.append({
|
||||
"idbusiness_ratings": rating_obj.idbusiness_ratings,
|
||||
"app_id": rating_obj.app_id,
|
||||
"business_id": rating_obj.business_id,
|
||||
"rating_title": rating_obj.rating_title,
|
||||
"rating_description": rating_obj.rating_description,
|
||||
"rating_score": rating_obj.rating_score,
|
||||
"date_time": rating_obj.date_time,
|
||||
"reviewer": user_obj.username,
|
||||
})
|
||||
if len(response_data) > 0:
|
||||
return response_data
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Business rating not found for the given business_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.post("/mzansi-directory/business-rating/insert/", tags=["Mzansi Directory"], status_code=201)
|
||||
async def insert_loyalty_card(itemRequest : BusinessRatingInsertRequest): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
nowDateTime = datetime.now()
|
||||
formatedDateTime = nowDateTime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
# Get No Of reviews for business
|
||||
businessReviewCountQueryResults = dbSession.query(BusinessRating).\
|
||||
filter(
|
||||
BusinessRating.business_id == itemRequest.business_id,
|
||||
).all()
|
||||
businessReviewCount = len(businessReviewCountQueryResults)
|
||||
print(f"Number of rows in business_ratings: {businessReviewCount}")
|
||||
dbSession.flush() # Ensure the session is flushed before adding new records
|
||||
# add business rating
|
||||
new_rating = BusinessRating(
|
||||
app_id=itemRequest.app_id,
|
||||
business_id=itemRequest.business_id,
|
||||
rating_title=itemRequest.rating_title,
|
||||
rating_description=itemRequest.rating_description,
|
||||
rating_score=itemRequest.rating_score,
|
||||
date_time=formatedDateTime
|
||||
)
|
||||
dbSession.add(new_rating)
|
||||
dbSession.flush() # Ensure the new rating is added to the session
|
||||
# Calc New Rating and update business rating
|
||||
newRating = ((float(itemRequest.current_rating) * businessReviewCount) + float(itemRequest.rating_score)) / (businessReviewCount + 1)
|
||||
businessToUpdate = dbSession.query(Business).filter(Business.business_id == itemRequest.business_id).first()
|
||||
if businessToUpdate:
|
||||
businessToUpdate.rating = str(newRating)
|
||||
dbSession.commit()
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Business not found for the given business_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to insert records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
@router.delete("/mzansi-directory/business-rating/delete/", tags=["Mzansi Directory"])
|
||||
async def Delete_loyalty_card(itemRequest : BusinessRatingDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
# Get No Of reviews for business
|
||||
businessReviewCountQueryResults = dbSession.query(BusinessRating).\
|
||||
filter(
|
||||
BusinessRating.business_id == itemRequest.business_id,
|
||||
).all()
|
||||
businessReviewCount = len(businessReviewCountQueryResults)
|
||||
print(f"Number of rows in business_ratings: {businessReviewCount}")
|
||||
dbSession.flush() # Ensure the session is flushed before adding new records
|
||||
# delete business rating
|
||||
rating_to_delete = dbSession.query(BusinessRating).\
|
||||
get(
|
||||
itemRequest.idbusiness_ratings
|
||||
)
|
||||
if not rating_to_delete:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Business rating with ID {itemRequest.idbusiness_ratings} not found."
|
||||
)
|
||||
dbSession.delete(rating_to_delete)
|
||||
dbSession.flush() # Ensure the new rating is added to the session
|
||||
# Calc New Rating and update business rating
|
||||
if(businessReviewCount <= 1):
|
||||
newRating = "0.0"
|
||||
else:
|
||||
newRating = ((float(itemRequest.current_rating) * businessReviewCount) - float(itemRequest.rating_score)) / (businessReviewCount - 1)
|
||||
businessToUpdate = dbSession.query(Business).filter(Business.business_id == itemRequest.business_id).first()
|
||||
if businessToUpdate:
|
||||
businessToUpdate.rating = str(newRating)
|
||||
dbSession.commit()
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Business not found for the given business_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to insert records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
return {"message": "Successfully Deleted Record"}
|
||||
|
||||
@router.put("/mzansi-directory/business-rating/update/", tags=["Mzansi Directory"])
|
||||
async def UpdatePatient(itemRequest : BusinessRatingUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
nowDateTime = datetime.now()
|
||||
formatedDateTime = nowDateTime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
# Get No Of reviews for business
|
||||
businessReviewCountQueryResults = dbSession.query(BusinessRating).\
|
||||
filter(
|
||||
BusinessRating.business_id == itemRequest.business_id,
|
||||
).all()
|
||||
businessReviewCount = len(businessReviewCountQueryResults)
|
||||
print(f"Number of rows in business_ratings: {businessReviewCount}")
|
||||
dbSession.flush() # Ensure the session is flushed before adding new records
|
||||
# Update business rating
|
||||
rating_to_update = dbSession.query(BusinessRating).\
|
||||
get(
|
||||
itemRequest.idbusiness_ratings
|
||||
)
|
||||
if rating_to_update:
|
||||
rating_to_update.rating_title = itemRequest.rating_title
|
||||
rating_to_update.rating_description = itemRequest.rating_description
|
||||
rating_to_update.rating_score = itemRequest.rating_new_score
|
||||
rating_to_update.date_time = formatedDateTime
|
||||
dbSession.flush() # Ensure the new rating is added to the session
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Business not found for the given business_id."
|
||||
)
|
||||
# Calc New Rating and update business rating
|
||||
newRating = ((float(itemRequest.current_rating) * businessReviewCount) - float(itemRequest.rating_old_score) + float(itemRequest.rating_new_score)) / (businessReviewCount)
|
||||
businessToUpdate = dbSession.query(Business).filter(Business.business_id == itemRequest.business_id).first()
|
||||
if businessToUpdate:
|
||||
businessToUpdate.rating = str(newRating)
|
||||
dbSession.commit()
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Business not found for the given business_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to insert records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
return {"message": "Successfully wUpdated Record"}
|
||||
|
||||
########################################################
|
||||
# Bookmarked Business #
|
||||
########################################################
|
||||
|
||||
@router.get("/mzansi-directory/bookmarked-business/{app_id}/{business_id}", tags=["Mzansi Directory"])
|
||||
async def read_all_ratings_by_business_id(app_id: str,business_id: str, session: SessionContainer = Depends(verify_session())): # , session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(BookmarkedBusiness, Business).\
|
||||
join(Business, BookmarkedBusiness.business_id == Business.business_id).\
|
||||
filter(
|
||||
BookmarkedBusiness.business_id == business_id,
|
||||
BookmarkedBusiness.app_id == app_id,
|
||||
).order_by(
|
||||
desc(BookmarkedBusiness.created_date)
|
||||
).first()
|
||||
if queryResults:
|
||||
bookmark_obj, bus_obj = queryResults
|
||||
return {
|
||||
"idbookmarked_businesses": bookmark_obj.idbookmarked_businesses,
|
||||
"app_id": bookmark_obj.app_id,
|
||||
"business_id": bookmark_obj.business_id,
|
||||
"business_name": bus_obj.Name,
|
||||
"created_date": bookmark_obj.created_date,
|
||||
}
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Bookmarked Business rating not found for the given app_id & business_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.get("/mzansi-directory/bookmarked-business/user/all/{app_id}/", tags=["Mzansi Directory"])
|
||||
async def read_all_ratings_by_business_id(app_id: str, session: SessionContainer = Depends(verify_session())): # , session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(BookmarkedBusiness, Business).\
|
||||
join(Business, BookmarkedBusiness.business_id == Business.business_id).\
|
||||
filter(
|
||||
BookmarkedBusiness.app_id == app_id,
|
||||
).order_by(
|
||||
desc(BookmarkedBusiness.created_date)
|
||||
).all()
|
||||
response_data = []
|
||||
for rating_obj, bus_obj in queryResults:
|
||||
response_data.append({
|
||||
"idbookmarked_businesses": rating_obj.idbookmarked_businesses,
|
||||
"app_id": rating_obj.app_id,
|
||||
"business_id": rating_obj.business_id,
|
||||
"business_name": bus_obj.Name,
|
||||
"created_date": rating_obj.created_date,
|
||||
})
|
||||
if len(response_data) > 0:
|
||||
return response_data
|
||||
else:
|
||||
# Return an empty response or a specific message
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Bookmarked Business not found for the given app_id."
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.post("/mzansi-directory/bookmarked-business/insert/", tags=["Mzansi Directory"], status_code=201)
|
||||
async def insert_loyalty_card(itemRequest : BookmarkedBusinessInsertRequest): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
nowDateTime = datetime.now()
|
||||
formatedDateTime = nowDateTime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
# add business rating
|
||||
new_bookmarked_business = BookmarkedBusiness(
|
||||
app_id=itemRequest.app_id,
|
||||
business_id=itemRequest.business_id,
|
||||
created_date=formatedDateTime
|
||||
)
|
||||
dbSession.add(new_bookmarked_business)
|
||||
dbSession.flush() # Ensure the new rating is added to the session
|
||||
dbSession.commit() # Commit the session to save changes
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to insert records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
@router.delete("/mzansi-directory/bookmarked-business/delete/", tags=["Mzansi Directory"])
|
||||
async def Delete_loyalty_card(itemRequest : BookmarkedBusinessDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
# delete business rating
|
||||
rating_to_delete = dbSession.query(BookmarkedBusiness).\
|
||||
get(
|
||||
itemRequest.idbookmarked_businesses
|
||||
)
|
||||
if not rating_to_delete:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Bookmarked Business with ID {itemRequest.idbusiness_ratings} not found."
|
||||
)
|
||||
dbSession.delete(rating_to_delete)
|
||||
dbSession.flush() # Ensure the new rating is added to the session
|
||||
dbSession.commit() # Commit the session to save changes
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to insert records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
return {"message": "Successfully Deleted Record"}
|
||||
@@ -1,177 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from datetime import date
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class LoyaltyCardDeleteRequest(BaseModel):
|
||||
idloyalty_cards: int
|
||||
|
||||
class MzansiWalletInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
shop_name: str
|
||||
card_number: str
|
||||
favourite: str
|
||||
priority_index: int
|
||||
nickname: str
|
||||
|
||||
class MzansiWalletUpdateRequest(BaseModel):
|
||||
idloyalty_cards: int
|
||||
favourite: str
|
||||
priority_index: int
|
||||
nickname: str
|
||||
card_number: str
|
||||
# class patientNoteUpdateRequest(BaseModel):
|
||||
# idpatient_notes: int
|
||||
# note_name: str
|
||||
# note_text: str
|
||||
# doc_office: str
|
||||
# doctor: str
|
||||
# patient_id: int
|
||||
|
||||
# Get List of all loyalty cards by user
|
||||
@router.get("/mzasni-wallet/loyalty-cards/{app_id}", tags=["Mzansi Wallet"])
|
||||
async def read_all_loyalty_cards_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())): # , session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbMzansiWalletConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM loyalty_cards where app_id = %s ORDER BY shop_name Asc"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idloyalty_cards": item[0],
|
||||
"app_id": item[1],
|
||||
"shop_name": item[2],
|
||||
"card_number": item[3],
|
||||
"favourite": item[4],
|
||||
"priority_index": item[5],
|
||||
"nickname": item[6],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of favourite loyalty cards by user
|
||||
@router.get("/mzasni-wallet/loyalty-cards/favourites/{app_id}", tags=["Mzansi Wallet"])
|
||||
async def read_favourite_loyalty_cards_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())): # , session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbMzansiWalletConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM loyalty_cards where app_id = %s and favourite != '' ORDER BY priority_index Asc"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idloyalty_cards": item[0],
|
||||
"app_id": item[1],
|
||||
"shop_name": item[2],
|
||||
"card_number": item[3],
|
||||
"favourite": item[4],
|
||||
"priority_index": item[5],
|
||||
"nickname": item[6],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all notes by patient
|
||||
# @router.get("/notes/patients-docOffice/", tags="patients_notes")
|
||||
# async def read_all_patientsby(itemRequest: noteRequest, session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "select patient_notes.idpatient_notes, patient_notes.note_name, patient_notes.note_text, patient_notes.patient_id, patient_notes.insert_date, patients.doc_office_id "
|
||||
# query += "from patient_manager.patient_notes "
|
||||
# query += "inner join patient_manager.patients "
|
||||
# query += "on patient_notes.patient_id = patients.idpatients "
|
||||
# query += "where patient_notes.patient_id = %s and patients.doc_office_id = %s"
|
||||
# cursor.execute(query, (itemRequest.patientID, itemRequest.DocOfficeID,))
|
||||
# items = [
|
||||
# {
|
||||
# "idpatient_notes": item[0],
|
||||
# "note_name": item[1],
|
||||
# "note_text": item[2],
|
||||
# "insert_date": item[3],
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# Insert loyalty cards into table
|
||||
@router.post("/mzasni-wallet/loyalty-cards/insert/", tags=["Mzansi Wallet"], status_code=201)
|
||||
async def insert_loyalty_card(itemRequest : MzansiWalletInsertRequest): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbMzansiWalletConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into loyalty_cards "
|
||||
query += "(app_id, shop_name, card_number, favourite, priority_index, nickname) "
|
||||
query += "values (%s, %s, %s, %s, %s, %s)"
|
||||
notetData = (itemRequest.app_id,
|
||||
itemRequest.shop_name,
|
||||
itemRequest.card_number,
|
||||
itemRequest.favourite,
|
||||
itemRequest.priority_index,
|
||||
itemRequest.nickname,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, notetData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
# return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
# Delete loyalty cards on table
|
||||
@router.delete("/mzasni-wallet/loyalty-cards/delete/", tags=["Mzansi Wallet"])
|
||||
async def Delete_loyalty_card(itemRequest : LoyaltyCardDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
# today = date.today()
|
||||
db = mih_database.dbConnection.dbMzansiWalletConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from loyalty_cards "
|
||||
query += "where idloyalty_cards=%s"
|
||||
# notetData = (itemRequest.idpatient_notes)
|
||||
try:
|
||||
cursor.execute(query, (str(itemRequest.idloyalty_cards),))
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Delete Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully deleted Record"}
|
||||
|
||||
# Update on table
|
||||
@router.put("/mzasni-wallet/loyalty-cards/update/", tags=["Mzansi Wallet"])
|
||||
async def UpdatePatient(itemRequest : MzansiWalletUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
||||
today = date.today()
|
||||
db = mih_database.dbConnection.dbMzansiWalletConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update loyalty_cards "
|
||||
query += "set favourite=%s, priority_index=%s, nickname=%s, card_number=%s "
|
||||
query += "where idloyalty_cards=%s"
|
||||
notetData = (itemRequest.favourite,
|
||||
itemRequest.priority_index,
|
||||
itemRequest.nickname,
|
||||
itemRequest.card_number,
|
||||
itemRequest.idloyalty_cards,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, notetData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
@@ -1,141 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime, timedelta
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class notificationsGetNuberedRequest(BaseModel):
|
||||
notification_count: str
|
||||
app_id: str
|
||||
|
||||
class notificationInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
notification_type: str
|
||||
notification_message: str
|
||||
action_path: str
|
||||
|
||||
# class patientUpdateRequest(BaseModel):
|
||||
# id_no: str
|
||||
# app_id: str
|
||||
# last_name: str
|
||||
# email: str
|
||||
# cell_no: str
|
||||
# medical_aid: str
|
||||
# medical_aid_main_member: str
|
||||
# medical_aid_no: str
|
||||
# medical_aid_code: str
|
||||
# medical_aid_name: str
|
||||
# medical_aid_scheme: str
|
||||
# address: str
|
||||
# app_id: str
|
||||
|
||||
# class patientDeleteRequest(BaseModel):
|
||||
# app_id: str
|
||||
|
||||
|
||||
# Get Notifications By app ID
|
||||
@router.get("/notifications/{app_id}", tags=["Notifications"])
|
||||
async def read_notifications_By_app_ID(app_id: str, amount: int, session: SessionContainer = Depends(verify_session())): # , session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
#query = "SELECT * FROM patients"
|
||||
query = "Select * from notifications "
|
||||
query += "where app_id = '%s' " % app_id
|
||||
query += "order by insert_date desc "
|
||||
query += "limit %s" % amount
|
||||
# return {"query": query}
|
||||
cursor.execute(query)
|
||||
items = [
|
||||
{
|
||||
"idnotifications": item[0],
|
||||
"app_id": item[1],
|
||||
"notification_message": item[2],
|
||||
"notification_read": item[3],
|
||||
"action_path": item[4],
|
||||
"insert_date": item[5],
|
||||
"notification_type": item[6],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
|
||||
# Insert Patient into table
|
||||
@router.post("/notifications/insert/", tags=["Notifications"], status_code=201)
|
||||
async def insert_Patient(itemRequest : notificationInsertRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
now = datetime.now() + timedelta(hours=2)
|
||||
notificationDateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(notificationDateTime)
|
||||
readType = "No"
|
||||
cursor = db.cursor()
|
||||
query = "insert into notifications "
|
||||
query += "(app_id, notification_message, notification_read, action_path, insert_date, notification_type) "
|
||||
query += "values (%s, %s, %s, %s, %s, %s)"
|
||||
patientData = (
|
||||
itemRequest.app_id,
|
||||
itemRequest.notification_message,
|
||||
readType,
|
||||
itemRequest.action_path,
|
||||
notificationDateTime,
|
||||
itemRequest.notification_type
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
# return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
# Update Patient on table
|
||||
@router.put("/notifications/update/{notification_id}", tags=["Notifications"])
|
||||
async def Update_Patient(notification_id : str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update notifications "
|
||||
query += "set notification_read=%s "
|
||||
query += "where idnotifications=%s"
|
||||
patientData = ("Yes",
|
||||
notification_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# # delete Patient on table
|
||||
# @router.delete("/patients/delete/", tags=["Patients"])
|
||||
# async def Delete_Patient(itemRequest : patientDeleteRequest, session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "delete from patients "
|
||||
# query += "where app_id=%s"
|
||||
# patientData = (itemRequest.app_id,
|
||||
# )
|
||||
# try:
|
||||
# cursor.execute(query, patientData)
|
||||
# except Exception as error:
|
||||
# raise HTTPException(status_code=404, detail="Failed to delete Record")
|
||||
# #return {"query": query, "message": error}
|
||||
# db.commit()
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return {"message": "Successfully delete Record"}
|
||||
@@ -1,242 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
from datetime import date, datetime, timedelta
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class accessRequestInsertRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
type: str
|
||||
requested_by: str
|
||||
|
||||
class accessRequestUpdateRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
status: str
|
||||
approved_by: str
|
||||
|
||||
class accessRequestReapplyRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
|
||||
@router.get("/access-requests/{access_type}/check/{business_id}", tags=["Patient Access"])
|
||||
async def check_business_id_has_access(access_type: str,business_id: str, app_id: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "select "
|
||||
query += "patient_business_access.business_id, business.Name, "
|
||||
query += "patient_business_access.app_id, users.fname, users.lname, "
|
||||
query += "patients.id_no, "
|
||||
query += "patient_business_access.type, patient_business_access.status, "
|
||||
query += "patient_business_access.approved_by, patient_business_access.approved_on, "
|
||||
query += "patient_business_access.requested_by, patient_business_access.requested_on "
|
||||
query += "from data_access.patient_business_access "
|
||||
query += "join app_data.business "
|
||||
query += "on patient_business_access.business_id = business.business_id "
|
||||
query += "join app_data.users "
|
||||
query += "on patient_business_access.app_id = users.app_id "
|
||||
query += "join patient_manager.patients "
|
||||
query += "on patient_business_access.app_id = patients.app_id "
|
||||
query += "where patient_business_access.type=%s and patient_business_access.business_id=%s and patient_business_access.app_id=%s"
|
||||
cursor.execute(query, (access_type,
|
||||
business_id,
|
||||
app_id,
|
||||
))
|
||||
items = [
|
||||
{
|
||||
"business_id": item[0],
|
||||
"business_name": item[1],
|
||||
"app_id": item[2],
|
||||
"fname": item[3],
|
||||
"lname": item[4],
|
||||
"id_no": item[5],
|
||||
"type": item[6],
|
||||
"status": item[7],
|
||||
"approved_by": item[8],
|
||||
"approved_on": item[9],
|
||||
"requested_by": item[10],
|
||||
"requested_on": item[11],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
@router.get("/access-requests/business/{access_type}/{business_id}", tags=["Patient Access"])
|
||||
async def read_all_patient_access_by_business_id(access_type: str,business_id: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "select "
|
||||
query += "patient_business_access.business_id, business.Name, "
|
||||
query += "patient_business_access.app_id, users.fname, users.lname, "
|
||||
query += "patients.id_no, "
|
||||
query += "patient_business_access.type, patient_business_access.status, "
|
||||
query += "patient_business_access.approved_by, patient_business_access.approved_on, "
|
||||
query += "patient_business_access.requested_by, patient_business_access.requested_on "
|
||||
query += "from data_access.patient_business_access "
|
||||
query += "join app_data.business "
|
||||
query += "on patient_business_access.business_id = business.business_id "
|
||||
query += "join app_data.users "
|
||||
query += "on patient_business_access.app_id = users.app_id "
|
||||
query += "join patient_manager.patients "
|
||||
query += "on patient_business_access.app_id = patients.app_id "
|
||||
query += "where patient_business_access.type=%s and patient_business_access.business_id=%s"
|
||||
cursor.execute(query, (access_type,
|
||||
business_id,))
|
||||
items = [
|
||||
{
|
||||
"business_id": item[0],
|
||||
"business_name": item[1],
|
||||
"app_id": item[2],
|
||||
"fname": item[3],
|
||||
"lname": item[4],
|
||||
"id_no": item[5],
|
||||
"type": item[6],
|
||||
"status": item[7],
|
||||
"approved_by": item[8],
|
||||
"approved_on": item[9],
|
||||
"requested_by": item[10],
|
||||
"requested_on": item[11],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
@router.get("/access-requests/personal/{access_type}/{app_id}", tags=["Patient Access"])
|
||||
async def read_all_patient_access_by_app_id(access_type: str,app_id: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "select "
|
||||
query += "patient_business_access.business_id, business.Name, "
|
||||
query += "patient_business_access.app_id, users.fname, users.lname, "
|
||||
query += "patients.id_no, "
|
||||
query += "patient_business_access.type, patient_business_access.status, "
|
||||
query += "patient_business_access.approved_by, patient_business_access.approved_on, "
|
||||
query += "patient_business_access.requested_by, patient_business_access.requested_on "
|
||||
query += "from data_access.patient_business_access "
|
||||
query += "join app_data.business "
|
||||
query += "on patient_business_access.business_id = business.business_id "
|
||||
query += "join app_data.users "
|
||||
query += "on patient_business_access.app_id = users.app_id "
|
||||
query += "join patient_manager.patients "
|
||||
query += "on patient_business_access.app_id = patients.app_id "
|
||||
query += "where patient_business_access.type=%s and patient_business_access.app_id=%s"
|
||||
cursor.execute(query, (access_type,
|
||||
app_id,))
|
||||
items = [
|
||||
{
|
||||
"business_id": item[0],
|
||||
"business_name": item[1],
|
||||
"app_id": item[2],
|
||||
"fname": item[3],
|
||||
"lname": item[4],
|
||||
"id_no": item[5],
|
||||
"type": item[6],
|
||||
"status": item[7],
|
||||
"approved_by": item[8],
|
||||
"approved_on": item[9],
|
||||
"requested_by": item[10],
|
||||
"requested_on": item[11],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Insert Patient into table
|
||||
@router.post("/access-requests/insert/", tags=["Patient Access"], status_code=201)
|
||||
async def insert_Patient_access(itemRequest : accessRequestInsertRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbDataAccessConnect()
|
||||
now = datetime.now() + timedelta(hours=2)
|
||||
notificationDateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(notificationDateTime)
|
||||
cursor = db.cursor()
|
||||
query = "insert into patient_business_access "
|
||||
query += "(business_id, app_id, type, status, approved_by, approved_on, requested_by, requested_on) "
|
||||
query += "values (%s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
patientData = (
|
||||
itemRequest.business_id,
|
||||
itemRequest.app_id,
|
||||
itemRequest.type,
|
||||
"pending",
|
||||
"",
|
||||
"9999-01-01 00:00:00",
|
||||
itemRequest.requested_by,
|
||||
now,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
# return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
# Update Patient on table
|
||||
@router.put("/access-requests/update/permission/", tags=["Patient Access"])
|
||||
async def Update_Patient_access(itemRequest: accessRequestUpdateRequest): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbDataAccessConnect()
|
||||
now = datetime.now() + timedelta(hours=2)
|
||||
notificationDateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(notificationDateTime)
|
||||
cursor = db.cursor()
|
||||
query = "update patient_business_access "
|
||||
query += "set status=%s, approved_by=%s, approved_on=%s "
|
||||
query += "where business_id=%s and app_id=%s"
|
||||
patientData = (itemRequest.status,
|
||||
itemRequest.approved_by,
|
||||
now,
|
||||
itemRequest.business_id,
|
||||
itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# Reapply Patient on table
|
||||
@router.put("/access-requests/re-apply/", tags=["Patient Access"])
|
||||
async def Reapply_Patient_access(itemRequest: accessRequestReapplyRequest): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbDataAccessConnect()
|
||||
now = datetime.now() + timedelta(hours=2)
|
||||
notificationDateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(notificationDateTime)
|
||||
cursor = db.cursor()
|
||||
query = "update patient_business_access "
|
||||
query += "set status='pending', approved_by='', approved_on='9999-01-01 00:00:00', requested_on=%s "
|
||||
query += "where business_id=%s and app_id=%s"
|
||||
patientData = (now,
|
||||
itemRequest.business_id,
|
||||
itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
@@ -1,298 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class patientInsertRequest(BaseModel):
|
||||
id_no: str
|
||||
first_name: str
|
||||
last_name: str
|
||||
email: str
|
||||
cell_no: str
|
||||
medical_aid: str
|
||||
medical_aid_main_member: str
|
||||
medical_aid_no: str
|
||||
medical_aid_code: str
|
||||
medical_aid_name: str
|
||||
medical_aid_scheme: str
|
||||
address: str
|
||||
app_id: str
|
||||
|
||||
class patientUpdateRequest(BaseModel):
|
||||
id_no: str
|
||||
first_name: str
|
||||
last_name: str
|
||||
email: str
|
||||
cell_no: str
|
||||
medical_aid: str
|
||||
medical_aid_main_member: str
|
||||
medical_aid_no: str
|
||||
medical_aid_code: str
|
||||
medical_aid_name: str
|
||||
medical_aid_scheme: str
|
||||
address: str
|
||||
app_id: str
|
||||
|
||||
class patientDeleteRequest(BaseModel):
|
||||
app_id: str
|
||||
|
||||
# # Get Patient By ID Number
|
||||
# @router.get("/patients/search/{search}", tags=["Patients"])
|
||||
# async def read_patientByID(search: str): #, session: SessionContainer = Depends(verify_session())
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM patients WHERE idpatients like %%%s%%" % search
|
||||
# #return {"query": query}
|
||||
# cursor.execute(query, (pat_id,))
|
||||
# item = cursor.fetchone()
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# if item is None:
|
||||
# raise HTTPException(status_code=404, detail="Item not found")
|
||||
# return {"idpatients": item[0],
|
||||
# "id_no": item[1],
|
||||
# "first_name": item[2],
|
||||
# "last_name": item[3],
|
||||
# "email": item[4],
|
||||
# "cell_no": item[5],
|
||||
# "medical_aid_name": item[6],
|
||||
# "medical_aid_no": item[7],
|
||||
# "medical_aid_scheme": item[8],
|
||||
# "address": item[9],
|
||||
# "doc_office_id": item[10]}
|
||||
|
||||
|
||||
# Get Patient By app ID
|
||||
@router.get("/patients/{app_id}", tags=["Patients"])
|
||||
async def read_patient_By_app_ID(app_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patients WHERE app_id=%s"
|
||||
cursor.execute(query, (app_id,))
|
||||
item = cursor.fetchone()
|
||||
cursor.close()
|
||||
db.close()
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return {"idpatients": item[0],
|
||||
"id_no": item[1],
|
||||
"first_name": item[2],
|
||||
"last_name": item[3],
|
||||
"email": item[4],
|
||||
"cell_no": item[5],
|
||||
"medical_aid_name": item[6],
|
||||
"medical_aid_no": item[7],
|
||||
"medical_aid_scheme": item[8],
|
||||
"address": item[9],
|
||||
"medical_aid": item[10],
|
||||
"medical_aid_main_member": item[11],
|
||||
"medical_aid_code": item[12],
|
||||
"app_id": item[13],}
|
||||
|
||||
# # Get Patient By ID Number
|
||||
# @router.get("/patients/email/{email}", tags="patients")
|
||||
# async def read_patientByID(email: str, session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM patients WHERE lower(email)=%s"
|
||||
# cursor.execute(query, (email.lower(),))
|
||||
# item = cursor.fetchone()
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# if item is None:
|
||||
# raise HTTPException(status_code=404, detail=("Item not found for "+ email))
|
||||
# return {"idpatients": item[0],
|
||||
# "id_no": item[1],
|
||||
# "first_name": item[2],
|
||||
# "last_name": item[3],
|
||||
# "email": item[4],
|
||||
# "cell_no": item[5],
|
||||
# "medical_aid_name": item[6],
|
||||
# "medical_aid_no": item[7],
|
||||
# "medical_aid_scheme": item[8],
|
||||
# "address": item[9],
|
||||
# "medical_aid": item[10],
|
||||
# "medical_aid_main_member": item[11],
|
||||
# "medical_aid_code": item[12],}
|
||||
|
||||
|
||||
# Get List of all patients
|
||||
@router.get("/patients/search/{search}", tags=["Patients"])
|
||||
async def read_all_patientsByUser(search: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
#query = "SELECT * FROM patients"
|
||||
query = "Select * from patients "
|
||||
query += "where id_no like '%%%s%%' " % search
|
||||
query += "or medical_aid_no like '%%%s%%'" % search
|
||||
# return {"query": query}
|
||||
cursor.execute(query)
|
||||
items = [
|
||||
{
|
||||
"idpatients": item[0],
|
||||
"id_no": item[1],
|
||||
"first_name": item[2],
|
||||
"last_name": item[3],
|
||||
"email": item[4],
|
||||
"cell_no": item[5],
|
||||
"medical_aid": item[10],
|
||||
"medical_aid_name": item[6],
|
||||
"medical_aid_no": item[7],
|
||||
"medical_aid_main_member": item[11],
|
||||
"medical_aid_code": item[12],
|
||||
"medical_aid_scheme": item[8],
|
||||
"address": item[9],
|
||||
"app_id": item[13],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# # Get List of all patients
|
||||
# @router.get("/patients/", tags="patients")
|
||||
# async def read_all_patients(session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM patients"
|
||||
# cursor.execute(query)
|
||||
# items = [
|
||||
# {
|
||||
# "idpatients": item[0],
|
||||
# "id_no": item[1],
|
||||
# "first_name": item[2],
|
||||
# "last_name": item[3],
|
||||
# "email": item[4],
|
||||
# "cell_no": item[5],
|
||||
# "medical_aid_name": item[6],
|
||||
# "medical_aid_no": item[7],
|
||||
# "medical_aid_scheme": item[8],
|
||||
# "address": item[9],
|
||||
# "doc_office_id": item[10]
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# # Get List of all patients by Doctors Office
|
||||
# @router.get("/patients/docOffice/{docoff_id}", tags="patients")
|
||||
# async def read_all_patientsby(docoff_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM patients where doc_office_id=%s"
|
||||
# cursor.execute(query, (docoff_id,))
|
||||
# items = [
|
||||
# {
|
||||
# "idpatients": item[0],
|
||||
# "id_no": item[1],
|
||||
# "first_name": item[2],
|
||||
# "last_name": item[3],
|
||||
# "email": item[4],
|
||||
# "cell_no": item[5],
|
||||
# "medical_aid_name": item[6],
|
||||
# "medical_aid_no": item[7],
|
||||
# "medical_aid_scheme": item[8],
|
||||
# "address": item[9],
|
||||
# "doc_office_id": item[10]
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# Insert Patient into table
|
||||
@router.post("/patients/insert/", tags=["Patients"], status_code=201)
|
||||
async def insert_Patient(itemRequest : patientInsertRequest, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into patients "
|
||||
query += "(id_no, first_name, last_name, email, cell_no, medical_aid, "
|
||||
query += "medical_aid_main_member, medical_aid_no, medical_aid_code, medical_aid_name, "
|
||||
query += "medical_aid_scheme, address, app_id) "
|
||||
query += "values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
patientData = (itemRequest.id_no,
|
||||
itemRequest.first_name,
|
||||
itemRequest.last_name,
|
||||
itemRequest.email,
|
||||
itemRequest.cell_no,
|
||||
itemRequest.medical_aid,
|
||||
itemRequest.medical_aid_main_member,
|
||||
itemRequest.medical_aid_no,
|
||||
itemRequest.medical_aid_code,
|
||||
itemRequest.medical_aid_name,
|
||||
itemRequest.medical_aid_scheme,
|
||||
itemRequest.address,
|
||||
itemRequest.app_id)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
#return {"message": "Failed to Create Record"}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
# Update Patient on table
|
||||
@router.put("/patients/update/", tags=["Patients"])
|
||||
async def Update_Patient(itemRequest : patientUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update patients "
|
||||
query += "set id_no=%s, first_name=%s, last_name=%s, email=%s, cell_no=%s, medical_aid=%s, "
|
||||
query += "medical_aid_main_member=%s, medical_aid_no=%s, medical_aid_code=%s, medical_aid_name=%s, "
|
||||
query += "medical_aid_scheme=%s, address=%s, app_id=%s "
|
||||
query += "where app_id=%s"
|
||||
patientData = (itemRequest.id_no,
|
||||
itemRequest.first_name,
|
||||
itemRequest.last_name,
|
||||
itemRequest.email,
|
||||
itemRequest.cell_no,
|
||||
itemRequest.medical_aid,
|
||||
itemRequest.medical_aid_main_member,
|
||||
itemRequest.medical_aid_no,
|
||||
itemRequest.medical_aid_code,
|
||||
itemRequest.medical_aid_name,
|
||||
itemRequest.medical_aid_scheme,
|
||||
itemRequest.address,
|
||||
itemRequest.app_id,
|
||||
itemRequest.app_id,)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# delete Patient on table
|
||||
@router.delete("/patients/delete/", tags=["Patients"])
|
||||
async def Delete_Patient(itemRequest : patientDeleteRequest, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from patients "
|
||||
query += "where app_id=%s"
|
||||
patientData = (itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to delete Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully delete Record"}
|
||||
@@ -1,132 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
from datetime import date
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class fileDeleteRequest(BaseModel):
|
||||
idpatient_files: int
|
||||
|
||||
class fileInsertRequest(BaseModel):
|
||||
file_path: str
|
||||
file_name: str
|
||||
app_id: str
|
||||
|
||||
# # Get List of all files
|
||||
# @router.get("/files/patients/", tags="patients_files")
|
||||
# async def read_all_files(session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM patient_files"
|
||||
# cursor.execute(query)
|
||||
# items = [
|
||||
# {
|
||||
# "idpatient_files": item[0],
|
||||
# "file_path": item[1],
|
||||
# "file_name": item[2],
|
||||
# "patient_id": item[3],
|
||||
# "insert_date": item[4],
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.get("/patient_files/get/{app_id}", tags=["Patients Files"])
|
||||
async def read_all_patient_files_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_files where app_id = %s ORDER BY insert_date DESC"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idpatient_files": item[0],
|
||||
"file_path": item[1],
|
||||
"file_name": item[2],
|
||||
"insert_date": item[3],
|
||||
"app_id": item[4],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# # Get List of all files by patient & DocOffice
|
||||
# @router.get("/files/patients-docOffice/", tags="patients_files")
|
||||
# async def read_all_files_by_patient(itemRequest: fileRequest, session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "select patient_files.idpatient_files, patient_files.file_path, patient_files.file_name, patient_files.patient_id, patient_files.insert_date, patients.doc_office_id "
|
||||
# query += "from patient_manager.patient_files "
|
||||
# query += "inner join patient_manager.patients "
|
||||
# query += "on patient_files.patient_id = patients.idpatients "
|
||||
# query += "where patient_files.patient_id = %s and patients.doc_office_id = %s"
|
||||
# cursor.execute(query, (itemRequest.patientID, itemRequest.DocOfficeID,))
|
||||
|
||||
# items = [
|
||||
# {
|
||||
# "idpatient_files": item[0],
|
||||
# "file_path": item[1],
|
||||
# "file_name": item[2],
|
||||
# "patient_id": item[3],
|
||||
# "insert_date": item[4],
|
||||
# "doc_office_id": item[5]
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# Delete Patient note on table
|
||||
@router.delete("/patient_files/delete/", tags=["Patients Files"])
|
||||
async def Delete_Patient_File(itemRequest : fileDeleteRequest, session: SessionContainer = Depends(verify_session())): #session: SessionContainer = Depends(verify_session())
|
||||
# today = date.today()
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from patient_files "
|
||||
query += "where idpatient_files=%s"
|
||||
# notetData = (itemRequest.idpatient_notes)
|
||||
try:
|
||||
cursor.execute(query, (str(itemRequest.idpatient_files),))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Delete Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully deleted Record"}
|
||||
|
||||
# Insert Patient note into table
|
||||
@router.post("/patient_files/insert/", tags=["Patients Files"], status_code=201)
|
||||
async def insert_Patient_Files(itemRequest : fileInsertRequest, session: SessionContainer = Depends(verify_session())):
|
||||
today = date.today()
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into patient_files "
|
||||
query += "(file_path, file_name, insert_date, app_id) "
|
||||
query += "values (%s, %s, %s, %s)"
|
||||
notetData = (itemRequest.file_path,
|
||||
itemRequest.file_name,
|
||||
today,
|
||||
itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, notetData)
|
||||
except Exception as error:
|
||||
#raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created file Record"}
|
||||
@@ -1,166 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from datetime import date
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class noteDeleteRequest(BaseModel):
|
||||
idpatient_notes: int
|
||||
|
||||
class patientNoteInsertRequest(BaseModel):
|
||||
note_name: str
|
||||
note_text: str
|
||||
doc_office: str
|
||||
doctor: str
|
||||
app_id: str
|
||||
|
||||
class patientNoteUpdateRequest(BaseModel):
|
||||
idpatient_notes: int
|
||||
note_name: str
|
||||
note_text: str
|
||||
doc_office: str
|
||||
doctor: str
|
||||
patient_id: int
|
||||
|
||||
# Get List of all notes
|
||||
# @router.get("/notes/patients/", tags="patients_notes")
|
||||
# async def read_all_notes(session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM patient_notes"
|
||||
# cursor.execute(query)
|
||||
# items = [
|
||||
# {
|
||||
# "idpatient_notes": item[0],
|
||||
# "note_name": item[1],
|
||||
# "note_text": item[2],
|
||||
# "insert_date": item[3],
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# Get List of all notes by patient
|
||||
@router.get("/notes/patients/{app_id}", tags=["Patients Notes"])
|
||||
async def read_all_patient_notes_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_notes where app_id = %s ORDER BY insert_date DESC"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idpatient_notes": item[0],
|
||||
"note_name": item[1],
|
||||
"note_text": item[2],
|
||||
"insert_date": item[3],
|
||||
"doc_office": item[5],
|
||||
"doctor": item[6],
|
||||
"app_id": item[4]
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all notes by patient
|
||||
# @router.get("/notes/patients-docOffice/", tags="patients_notes")
|
||||
# async def read_all_patientsby(itemRequest: noteRequest, session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "select patient_notes.idpatient_notes, patient_notes.note_name, patient_notes.note_text, patient_notes.patient_id, patient_notes.insert_date, patients.doc_office_id "
|
||||
# query += "from patient_manager.patient_notes "
|
||||
# query += "inner join patient_manager.patients "
|
||||
# query += "on patient_notes.patient_id = patients.idpatients "
|
||||
# query += "where patient_notes.patient_id = %s and patients.doc_office_id = %s"
|
||||
# cursor.execute(query, (itemRequest.patientID, itemRequest.DocOfficeID,))
|
||||
# items = [
|
||||
# {
|
||||
# "idpatient_notes": item[0],
|
||||
# "note_name": item[1],
|
||||
# "note_text": item[2],
|
||||
# "insert_date": item[3],
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items
|
||||
|
||||
# Insert Patient note into table
|
||||
@router.post("/notes/insert/", tags=["Patients Notes"], status_code=201)
|
||||
async def insert_Patient_Note(itemRequest : patientNoteInsertRequest, session: SessionContainer = Depends(verify_session())):
|
||||
today = date.today()
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into patient_notes "
|
||||
query += "(note_name, note_text, insert_date, doc_office, doctor, app_id) "
|
||||
query += "values (%s, %s, %s, %s, %s, %s)"
|
||||
notetData = (itemRequest.note_name,
|
||||
itemRequest.note_text,
|
||||
today,
|
||||
itemRequest.doc_office,
|
||||
itemRequest.doctor,
|
||||
itemRequest.app_id,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, notetData)
|
||||
except Exception as error:
|
||||
#raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
# Delete Patient note on table
|
||||
@router.delete("/notes/delete/", tags=["Patients Notes"])
|
||||
async def Delete_Patient_note(itemRequest : noteDeleteRequest, session: SessionContainer = Depends(verify_session()) ): #session: SessionContainer = Depends(verify_session())
|
||||
# today = date.today()
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from patient_notes "
|
||||
query += "where idpatient_notes=%s"
|
||||
# notetData = (itemRequest.idpatient_notes)
|
||||
try:
|
||||
cursor.execute(query, (str(itemRequest.idpatient_notes),))
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Delete Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully deleted Record"}
|
||||
|
||||
# Update Patient note on table
|
||||
# @router.put("/notes/update/", tags="patients_notes")
|
||||
# async def UpdatePatient(itemRequest : patientNoteUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
||||
# today = date.today()
|
||||
# db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "update patient_notes "
|
||||
# query += "set note_name=%s, note_text=%s, patient_id=%s, insert_date=%s "
|
||||
# query += "where idpatient_notes=%s"
|
||||
# notetData = (itemRequest.note_name,
|
||||
# itemRequest.note_text,
|
||||
# itemRequest.patient_id,
|
||||
# today,
|
||||
# itemRequest.idpatient_notes)
|
||||
# try:
|
||||
# cursor.execute(query, notetData)
|
||||
# except Exception as error:
|
||||
# raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
# #return {"query": query, "message": error}
|
||||
# db.commit()
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return {"message": "Successfully Updated Record"}
|
||||
@@ -1,172 +0,0 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
from datetime import datetime, timedelta, date
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class fileDeleteRequest(BaseModel):
|
||||
idpatient_files: int
|
||||
|
||||
class queueInsertRequest(BaseModel):
|
||||
business_id: str
|
||||
app_id: str
|
||||
date: str
|
||||
time: str
|
||||
|
||||
class queueUpdateRequest(BaseModel):
|
||||
idpatient_queue: int
|
||||
date: str
|
||||
time: str
|
||||
|
||||
class queueDeleteRequest(BaseModel):
|
||||
idpatient_queue: int
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.get("/queue/appointments/business/{business_id}", tags=["Patients Queue"])
|
||||
async def read_all_patient_queue_by_business_id(business_id: str, date: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
requestDate = datetime.strptime(date, '%Y-%m-%d').date()
|
||||
#print("request date: " + str(requestDate))
|
||||
cursor = db.cursor()
|
||||
# query = "SELECT patient_queue.idpatient_queue, patient_queue.business_id, "
|
||||
# query += "patient_queue.app_id, patient_queue.date_time, "
|
||||
# query += "patients.id_no, patients.first_name, patients.last_name, patients.medical_aid_no "
|
||||
# query += "from patient_manager.patient_queue "
|
||||
# query += "inner join patient_manager.patients "
|
||||
# query += "on patient_queue.app_id = patients.app_id "
|
||||
query = "SELECT patient_queue.idpatient_queue, patient_queue.business_id, "
|
||||
query += "patient_queue.app_id, patient_queue.date_time, "
|
||||
query += "patients.id_no, patients.first_name, patients.last_name, patients.medical_aid_no, business.Name "
|
||||
query += "from patient_manager.patient_queue "
|
||||
query += "join patient_manager.patients "
|
||||
query += "on patient_queue.app_id = patients.app_id "
|
||||
query += "join app_data.business "
|
||||
query += "on patient_queue.business_id = business.business_id "
|
||||
query = query + "where patient_queue.business_id = %s and date_time like '" + str(requestDate) + "%' "
|
||||
query += "ORDER BY date_time ASC"
|
||||
cursor.execute(query, (business_id,))
|
||||
items = [
|
||||
{
|
||||
"idpatient_queue": item[0],
|
||||
"business_id": item[1],
|
||||
"app_id": item[2],
|
||||
"date_time": item[3],
|
||||
"id_no": item[4],
|
||||
"first_name": item[5],
|
||||
"last_name": item[6],
|
||||
"medical_aid_no": item[7],
|
||||
"business_name": item[8],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all files by patient
|
||||
@router.get("/queue/appointments/personal/{app_id}", tags=["Patients Queue"])
|
||||
async def read_all_patient_queue_by_business_id(app_id: str, date: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
requestDate = datetime.strptime(date, '%Y-%m-%d').date()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT patient_queue.idpatient_queue, patient_queue.business_id, "
|
||||
query += "patient_queue.app_id, patient_queue.date_time, "
|
||||
query += "patients.id_no, patients.first_name, patients.last_name, patients.medical_aid_no, business.Name "
|
||||
query += "from patient_manager.patient_queue "
|
||||
query += "join patient_manager.patients "
|
||||
query += "on patient_queue.app_id = patients.app_id "
|
||||
query += "join app_data.business "
|
||||
query += "on patient_queue.business_id = business.business_id "
|
||||
query = query + "where patient_queue.app_id = %s and date_time like '" + str(requestDate) + "%' "
|
||||
query += "ORDER BY date_time ASC"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idpatient_queue": item[0],
|
||||
"business_id": item[1],
|
||||
"app_id": item[2],
|
||||
"date_time": item[3],
|
||||
"id_no": item[4],
|
||||
"first_name": item[5],
|
||||
"last_name": item[6],
|
||||
"medical_aid_no": item[7],
|
||||
"business_name": item[8],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Insert Patient note into table
|
||||
@router.post("/queue/appointment/insert/", tags=["Patients Queue"], status_code=201)
|
||||
async def insert_Patient_Files(itemRequest : queueInsertRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
date_time = itemRequest.date + " " + itemRequest.time + ":00"
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into patient_queue "
|
||||
query += "(business_id, app_id, date_time) "
|
||||
query += "values (%s, %s, %s)"
|
||||
notetData = (itemRequest.business_id,
|
||||
itemRequest.app_id,
|
||||
date_time,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, notetData)
|
||||
except Exception as error:
|
||||
#raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
return {"message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created file Record"}
|
||||
|
||||
# Update Patient on table
|
||||
@router.put("/queue/appointment/update/", tags=["Patients Queue"])
|
||||
async def Update_Queue(itemRequest : queueUpdateRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
|
||||
date_time = itemRequest.date + " " + itemRequest.time + ":00"
|
||||
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update patient_queue "
|
||||
query += "set date_time=%s "
|
||||
query += "where idpatient_queue=%s"
|
||||
patientData = (date_time,
|
||||
itemRequest.idpatient_queue)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# Update Patient on table
|
||||
@router.delete("/queue/appointment/delete/", tags=["Patients Queue"])
|
||||
async def Delete_Queue(itemRequest : queueDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbPatientManagerConnect()
|
||||
cursor = db.cursor()
|
||||
query = "delete from patient_queue "
|
||||
query += "where idpatient_queue=%s"
|
||||
try:
|
||||
cursor.execute(query, (str(itemRequest.idpatient_queue),))
|
||||
except Exception as error:
|
||||
print(error)
|
||||
raise HTTPException(status_code=404, detail="Failed to Delete Appointment")
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully deleted Appointment"}
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
import mih_database.mihDbConnections
|
||||
from mih_database.mihDbObjects import UserConsent
|
||||
from sqlalchemy import desc, or_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class userConsentInsertRequest(BaseModel):
|
||||
app_id: str
|
||||
privacy_policy_accepted: datetime
|
||||
terms_of_services_accepted: datetime
|
||||
|
||||
class userConsentUpdateRequest(BaseModel):
|
||||
app_id: str
|
||||
privacy_policy_accepted: datetime
|
||||
terms_of_services_accepted: datetime
|
||||
|
||||
@router.get("/user-consent/user/{app_id}", tags=["User Consent"])
|
||||
async def get_user_consent(app_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(UserConsent).\
|
||||
filter(UserConsent.app_id == app_id).\
|
||||
first()
|
||||
if queryResults:
|
||||
return {
|
||||
"idUserConsent": queryResults.iduser_consent,
|
||||
"app_id": queryResults.app_id,
|
||||
"privacy_policy_accepted": queryResults.privacy_policy_accepted,
|
||||
"terms_of_services_accepted": queryResults.terms_of_services_accepted
|
||||
}
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User Consent not found")
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.post("/user-consent/insert/",
|
||||
tags=["User Consent"],
|
||||
status_code=status.HTTP_201_CREATED)
|
||||
async def insert_user_consent(itemRequest: userConsentInsertRequest,
|
||||
session: SessionContainer = Depends(verify_session())):
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
newUserConsent = UserConsent(
|
||||
app_id = itemRequest.app_id,
|
||||
privacy_policy_accepted = itemRequest.privacy_policy_accepted,
|
||||
terms_of_services_accepted = itemRequest.terms_of_services_accepted,
|
||||
)
|
||||
dbSession.add(newUserConsent)
|
||||
dbSession.commit()
|
||||
dbSession.refresh(newUserConsent)
|
||||
return {"message": "Successfully Created file Record"}
|
||||
except IntegrityError as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT, # 409 Conflict is often suitable for constraint errors
|
||||
detail=f"Data integrity error: The provided data violates a database constraint. Details: {e.orig}"
|
||||
) from e
|
||||
except SQLAlchemyError as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"A database error occurred during insertion. Details: {e.orig}"
|
||||
) from e
|
||||
except Exception as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"An unexpected error occurred: {e}"
|
||||
) from e
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
@router.put("/user-consent/update/", tags=["User Consent"])
|
||||
async def update_user_consent(itemRequest: userConsentUpdateRequest,
|
||||
session: SessionContainer = Depends(verify_session())):
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
# pp_accepted_dt = datetime.strptime(itemRequest.privacy_policy_accepted, "%Y-%m-%d %H:%M:%S")
|
||||
# tos_accepted_dt = datetime.strptime(itemRequest.terms_of_services_accepted, "%Y-%m-%d %H:%M:%S")
|
||||
try:
|
||||
existing_consent = dbSession.query(UserConsent).filter(UserConsent.app_id == itemRequest.app_id).first()
|
||||
if not existing_consent:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User Consent not found")
|
||||
|
||||
existing_consent.privacy_policy_accepted = itemRequest.privacy_policy_accepted
|
||||
existing_consent.terms_of_services_accepted = itemRequest.terms_of_services_accepted
|
||||
|
||||
dbSession.commit()
|
||||
return {"message": "Successfully Updated User Consent Record"}
|
||||
except HTTPException as http_exc:
|
||||
# Re-raise HTTPException directly if it was raised within the try block
|
||||
raise http_exc
|
||||
except IntegrityError as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail=f"Data integrity error: The provided data violates a database constraint. Details: {e.orig}"
|
||||
) from e
|
||||
except SQLAlchemyError as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"A database error occurred during update. Details: {e.orig}"
|
||||
) from e
|
||||
except Exception as e:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"An unexpected error occurred: {e}"
|
||||
) from e
|
||||
finally:
|
||||
dbSession.close()
|
||||
@@ -1,280 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from pydantic import BaseModel
|
||||
#from ..mih_database import dbConnection
|
||||
import mih_database
|
||||
import mih_database.mihDbConnections
|
||||
from mih_database.mihDbObjects import User, Business, BusinessRating, BookmarkedBusiness
|
||||
from sqlalchemy import desc, or_
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql import func
|
||||
#SuperToken Auth from front end
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from supertokens_python.asyncio import delete_user
|
||||
|
||||
from fastapi import Depends
|
||||
|
||||
import mih_database.dbConnection
|
||||
import Minio_Storage.minioConnection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class userRequest(BaseModel):
|
||||
email: str
|
||||
DocOfficeID: int
|
||||
|
||||
class userInsertRequest(BaseModel):
|
||||
email: str
|
||||
app_id: str
|
||||
|
||||
class userUpdateRequestV2(BaseModel):
|
||||
idusers: int
|
||||
username: str
|
||||
fnam: str
|
||||
lname: str
|
||||
type: str
|
||||
pro_pic_path: str
|
||||
purpose: str
|
||||
|
||||
class userUpdateRequest(BaseModel):
|
||||
idusers: int
|
||||
username: str
|
||||
fnam: str
|
||||
lname: str
|
||||
type: str
|
||||
pro_pic_path: str
|
||||
|
||||
class userDeleteRequest(BaseModel):
|
||||
app_id: str
|
||||
env: str
|
||||
|
||||
# #get user by email & doc Office ID
|
||||
# @router.get("/users/profile/{email}", tags="users")
|
||||
# async def read_all_users(email: str, session: SessionContainer = Depends(verify_session())):
|
||||
# db = mih_database.dbConnection.dbAppDataConnect()
|
||||
# cursor = db.cursor()
|
||||
# query = "SELECT * FROM users where email = %s"
|
||||
# cursor.execute(query, (email.lower(),))
|
||||
# items = [
|
||||
# {"idusers": item[0],
|
||||
# "email": item[1],
|
||||
# "docOffice_id": item[2],
|
||||
# "fname":item[3],
|
||||
# "lname":item[4],
|
||||
# "type": item[5],
|
||||
# "app_id": item[6],
|
||||
# "username": item[7],
|
||||
# }
|
||||
# for item in cursor.fetchall()
|
||||
# ]#
|
||||
# cursor.close()
|
||||
# db.close()
|
||||
# return items[0]
|
||||
|
||||
|
||||
|
||||
@router.get("/users/count/", tags=["MIH Users"])
|
||||
async def read_users_by_app_id(): #, session: SessionContainer = Depends(verify_session())
|
||||
dbEngine = mih_database.mihDbConnections.dbAllConnect()
|
||||
dbSession = Session(dbEngine)
|
||||
try:
|
||||
queryResults = dbSession.query(func.count(User.app_id)).scalar()
|
||||
response_data = {"count": queryResults}
|
||||
return response_data
|
||||
except Exception as e:
|
||||
print(f"An error occurred during the ORM query: {e}")
|
||||
if dbSession.is_active:
|
||||
dbSession.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to retrieve records due to an internal server error."
|
||||
)
|
||||
finally:
|
||||
dbSession.close()
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/users/search/{search}", tags=["MIH Users"])
|
||||
async def read_all_users(search: str, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = ""
|
||||
query += "SELECT * FROM users "
|
||||
query += "WHERE (LOWER(email) LIKE %s OR LOWER(username) LIKE %s "
|
||||
query += "OR LOWER(fname) LIKE %s OR LOWER(lname) LIKE %s "
|
||||
query += "OR LOWER(purpose) LIKE %s) "
|
||||
query += "AND username != ''"
|
||||
search_term = f"%{search.lower()}%" # Add wildcards and lowercase
|
||||
cursor.execute(query, (search_term, search_term,search_term, search_term, search_term))
|
||||
items = [
|
||||
{
|
||||
"idUser": item[0],
|
||||
"email": item[1],
|
||||
"fname": item[2],
|
||||
"lname": item[3],
|
||||
"type": item[4],
|
||||
"app_id": item[5],
|
||||
"username": item[6],
|
||||
"pro_pic_path": item[7],
|
||||
"purpose": item[8],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/users/validate/username/{username}", tags=["MIH Users"])
|
||||
async def read_all_users(username: str, session: SessionContainer = Depends(verify_session()) ): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM users WHERE LOWER(username) = %s"
|
||||
# search_term = f"%{username.lower()}%" # Add wildcards and lowercase
|
||||
cursor.execute(query, (username.lower(),))
|
||||
available = cursor.fetchone() is None
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"available": available}
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/user/{app_id}", tags=["MIH Users"])
|
||||
async def read_users_by_app_id(app_id: str, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM users where app_id = %s"
|
||||
cursor.execute(query, (app_id,))
|
||||
items = [
|
||||
{
|
||||
"idUser": item[0],
|
||||
"email": item[1],
|
||||
"fname": item[2],
|
||||
"lname": item[3],
|
||||
"type": item[4],
|
||||
"app_id": item[5],
|
||||
"username": item[6],
|
||||
"pro_pic_path": item[7],
|
||||
"purpose": item[8],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items[0]
|
||||
|
||||
# Insert Patient into table
|
||||
@router.post("/user/insert/", tags=["MIH Users"], status_code=201)
|
||||
async def insert_User_details(itemRequest : userInsertRequest, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into users "
|
||||
query += "(email, fname, lname, type, app_id, username, pro_pic_path, purpose) "
|
||||
query += "values (%s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
userData = (itemRequest.email,"","","personal",
|
||||
itemRequest.app_id, "", "","")
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record - " + error)
|
||||
#return {"message": "Failed to Create Record"}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
|
||||
# Update User on table
|
||||
@router.put("/user/update/v2/", tags=["MIH Users"])
|
||||
async def Update_User_details(itemRequest : userUpdateRequestV2, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update users "
|
||||
query += "set username=%s, fname=%s, lname=%s, type=%s, pro_pic_path=%s, purpose=%s "
|
||||
query += "where idusers=%s"
|
||||
userData = (itemRequest.username,
|
||||
itemRequest.fnam,
|
||||
itemRequest.lname,
|
||||
itemRequest.type,
|
||||
itemRequest.pro_pic_path,
|
||||
itemRequest.purpose,
|
||||
itemRequest.idusers,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# Update User on table
|
||||
@router.put("/user/update/", tags=["MIH Users"])
|
||||
async def Update_User_details(itemRequest : userUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
||||
db = mih_database.dbConnection.dbAppDataConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update users "
|
||||
query += "set username=%s, fname=%s, lname=%s, type=%s, pro_pic_path=%s "
|
||||
query += "where idusers=%s"
|
||||
userData = (itemRequest.username,
|
||||
itemRequest.fnam,
|
||||
itemRequest.lname,
|
||||
itemRequest.type,
|
||||
itemRequest.pro_pic_path,
|
||||
itemRequest.idusers,
|
||||
)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail=error)
|
||||
#return {"query": query, "message": error}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Updated Record"}
|
||||
|
||||
# Get List of all files
|
||||
@router.delete("/user/delete/all/", tags=["MIH Users"])
|
||||
async def delete_users_data_by_app_id(itemRequest: userDeleteRequest, session: SessionContainer = Depends(verify_session())): #, session: SessionContainer = Depends(verify_session())
|
||||
db = mih_database.dbConnection.dbAllConnect()
|
||||
cursor = db.cursor()
|
||||
db.start_transaction()
|
||||
try:
|
||||
queries = [
|
||||
"DELETE FROM app_data.notifications where app_id = %s",
|
||||
"DELETE FROM app_data.business_users where app_id = %s",
|
||||
"DELETE FROM data_access.patient_business_access where app_id = %s",
|
||||
"DELETE FROM mzansi_calendar.appointments where app_id = %s",
|
||||
"DELETE FROM mzansi_wallet.loyalty_cards where app_id = %s",
|
||||
"DELETE FROM patient_manager.patients where app_id = %s",
|
||||
"DELETE FROM patient_manager.patient_notes where app_id = %s",
|
||||
"DELETE FROM patient_manager.patient_files where app_id = %s",
|
||||
"DELETE FROM patient_manager.claim_statement_file where app_id = %s",
|
||||
"DELETE FROM app_data.user_consent where app_id = %s",
|
||||
"DELETE FROM app_data.users where app_id = %s",
|
||||
]
|
||||
# Delete user from all tables
|
||||
for query in queries:
|
||||
cursor.execute(query, (itemRequest.app_id,))
|
||||
# Delete user files
|
||||
try:
|
||||
client = Minio_Storage.minioConnection.minioConnect(itemRequest.env)
|
||||
objects_to_delete = client.list_objects("mih", prefix=itemRequest.app_id, recursive=True)
|
||||
for obj in objects_to_delete:
|
||||
client.remove_object("mih", obj.object_name)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=500, detail="Failed to delete files from Minio - " + str(error))
|
||||
# Delete user from SuperTokens
|
||||
try:
|
||||
await delete_user(itemRequest.app_id)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=500, detail="Failed to delete user from SuperTokens - " + str(error))
|
||||
db.commit()
|
||||
except Exception as error:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=str(error))
|
||||
finally:
|
||||
if cursor:
|
||||
cursor.close()
|
||||
if db:
|
||||
db.close()
|
||||
return {"message": "Successfully Deleted User Account, Data & Files"}
|
||||
|
Before Width: | Height: | Size: 392 KiB |
50
mih_ui/.gitignore
vendored
@@ -1,50 +0,0 @@
|
||||
.env
|
||||
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.build/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
.swiftpm/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
**/doc/api/
|
||||
**/ios/Flutter/.last_build_id
|
||||
.dart_tool/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
.pub-cache/
|
||||
.pub/
|
||||
/build/
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
|
||||
# Obfuscation related
|
||||
app.*.map.json
|
||||
|
||||
# Android Studio will place build artifacts here
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
|
||||
# Flutter config file
|
||||
/config/
|
||||
@@ -1,30 +0,0 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: "6fba2447e95c451518584c35e25f5433f14d888c"
|
||||
channel: "stable"
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: 6fba2447e95c451518584c35e25f5433f14d888c
|
||||
base_revision: 6fba2447e95c451518584c35e25f5433f14d888c
|
||||
- platform: linux
|
||||
create_revision: 6fba2447e95c451518584c35e25f5433f14d888c
|
||||
base_revision: 6fba2447e95c451518584c35e25f5433f14d888c
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
@@ -1,36 +0,0 @@
|
||||
# --- STAGE 1: The Builder ---
|
||||
FROM debian:latest AS build-env
|
||||
|
||||
# Install necessary dependencies for Flutter
|
||||
RUN apt-get update && apt-get install -y \
|
||||
curl git wget unzip libglu1-mesa fonts-droid-fallback python3 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Clone Flutter SDK
|
||||
RUN git clone -b flutter-3.32-candidate.0 https://github.com/flutter/flutter.git /usr/local/flutter
|
||||
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"
|
||||
|
||||
# Build the Flutter web app
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN flutter config --enable-web
|
||||
RUN flutter build web --release -t ./lib/main_prod.dart
|
||||
|
||||
# --- STAGE 2: The Final Production Image ---
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy built files from the first stage
|
||||
COPY --from=build-env /app/build/web /usr/share/nginx/html
|
||||
|
||||
# Create the Nginx config inside the Dockerfile to handle SPA routing
|
||||
RUN echo 'server { \
|
||||
listen 83; \
|
||||
location / { \
|
||||
root /usr/share/nginx/html; \
|
||||
index index.html; \
|
||||
try_files $uri $uri/ /index.html; \
|
||||
} \
|
||||
}' > /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 83
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -1,16 +0,0 @@
|
||||
# mzansi_innovation_hub
|
||||
|
||||
A new Flutter project.
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
@@ -1,28 +0,0 @@
|
||||
# This file configures the analyzer, which statically analyzes Dart code to
|
||||
# check for errors, warnings, and lints.
|
||||
#
|
||||
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
|
||||
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
|
||||
# invoked from the command line by running `flutter analyze`.
|
||||
|
||||
# The following line activates a set of recommended lints for Flutter apps,
|
||||
# packages, and plugins designed to encourage good coding practices.
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
linter:
|
||||
# The lint rules applied to this project can be customized in the
|
||||
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
|
||||
# included above or to enable additional rules. A list of all available lints
|
||||
# and their documentation is published at https://dart.dev/lints.
|
||||
#
|
||||
# Instead of disabling a lint rule for the entire project in the
|
||||
# section below, it can also be suppressed for a single line of code
|
||||
# or a specific dart file by using the `// ignore: name_of_lint` and
|
||||
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
|
||||
# producing the lint.
|
||||
rules:
|
||||
# avoid_print: false # Uncomment to disable the `avoid_print` rule
|
||||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||
|
||||
# Additional information about this file can be found at
|
||||
# https://dart.dev/guides/language/analysis-options
|
||||
14
mih_ui/android/.gitignore
vendored
@@ -1,14 +0,0 @@
|
||||
gradle-wrapper.jar
|
||||
/.gradle
|
||||
/captures/
|
||||
/gradlew
|
||||
/gradlew.bat
|
||||
/local.properties
|
||||
GeneratedPluginRegistrant.java
|
||||
.cxx/
|
||||
|
||||
# Remember to never publicly share your keystore.
|
||||
# See https://flutter.dev/to/reference-keystore
|
||||
key.properties
|
||||
**/*.keystore
|
||||
**/*.jks
|
||||
@@ -1,72 +0,0 @@
|
||||
import java.util.Properties
|
||||
import java.io.FileInputStream
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
// START: FlutterFire Configuration
|
||||
id("com.google.gms.google-services")
|
||||
// END: FlutterFire Configuration
|
||||
id("kotlin-android")
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
id("dev.flutter.flutter-gradle-plugin")
|
||||
}
|
||||
|
||||
val keystoreProperties = Properties()
|
||||
val keystorePropertiesFile = rootProject.file("key.properties")
|
||||
if (keystorePropertiesFile.exists()) {
|
||||
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "za.co.mzansiinnovationhub.mih"
|
||||
compileSdk = 35
|
||||
ndkVersion = "27.0.12077973"
|
||||
// ndkVersion = flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId = "za.co.mzansiinnovationhub.mih"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||
minSdk = 23
|
||||
//minSdk = flutter.minSdkVersion
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
versionCode = flutter.versionCode
|
||||
versionName = flutter.versionName
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
keyAlias = keystoreProperties["keyAlias"] as String
|
||||
keyPassword = keystoreProperties["keyPassword"] as String
|
||||
storeFile = keystoreProperties["storeFile"]?.let { file(it) }
|
||||
storePassword = keystoreProperties["storePassword"] as String
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
isMinifyEnabled = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "33677883408",
|
||||
"project_id": "mzansi-innovation-hub",
|
||||
"storage_bucket": "mzansi-innovation-hub.firebasestorage.app"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:33677883408:android:ebd8565991c56257223295",
|
||||
"android_client_info": {
|
||||
"package_name": "za.co.mzansiinnovationhub.mih"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyBUkjWdu9YcgiF-e9TC5hoiEoCjPyjA5hU"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
5
mih_ui/android/app/proguard-rules.pro
vendored
@@ -1,5 +0,0 @@
|
||||
# R8/ProGuard rules to prevent removal of necessary Facebook Infer annotations
|
||||
-keep class com.facebook.infer.annotation.** { *; }
|
||||
-keep interface com.facebook.infer.annotation.** { *; }
|
||||
-dontwarn com.facebook.infer.annotation.Nullsafe$Mode
|
||||
-dontwarn com.facebook.infer.annotation.Nullsafe
|
||||
@@ -1,7 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
@@ -1,117 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- <uses-permission android:name="com.google.android.gms.permission.AD_ID"
|
||||
tools:node="merge"/> -->
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions"/>
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> -->
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
tools:replace="android:maxSdkVersion"
|
||||
android:maxSdkVersion="29"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32"
|
||||
tools:replace="android:maxSdkVersion" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
|
||||
|
||||
<application
|
||||
android:label="MIH"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/launcher_icon"
|
||||
android:enableOnBackInvokedCallback="true">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:taskAffinity=""
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
to determine the Window background behind the Flutter UI. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="flutter-deeplink"
|
||||
android:value="true"
|
||||
/>
|
||||
<!-- Shortcut Icons -->
|
||||
<meta-data
|
||||
android:name="mih_shortcut_icons"
|
||||
android:resource="@array/mih_shortcut_icons" />
|
||||
<!-- New Deep Linking -->
|
||||
<intent-filter android:autoVerify="true">
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="http" android:host="app.mzansi-innovation-hub.co.za" />
|
||||
<data android:scheme="https" android:host="app.mzansi-innovation-hub.co.za" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="http" android:host="app.mzansi-innovation-hub.co.za" />
|
||||
<data android:scheme="https" android:host="app.mzansi-innovation-hub.co.za" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.ads.APPLICATION_ID"
|
||||
android:value="ca-app-pub-4781880856775334~7553757584"/>
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
||||
|
||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
||||
<queries>
|
||||
<!-- If your app checks for SMS support -->
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data android:scheme="sms" />
|
||||
</intent>
|
||||
<!-- If your app checks for call support -->
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data android:scheme="tel" />
|
||||
</intent>
|
||||
<!-- If your application checks for inAppBrowserView launch mode support -->
|
||||
<intent>
|
||||
<action android:name="android.support.customtabs.action.CustomTabsService" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.TTS_SERVICE" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.speech.RecognitionService" />
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
||||
@@ -1,5 +0,0 @@
|
||||
package za.co.mzansiinnovationhub.mih
|
||||
|
||||
import io.flutter.embedding.android.FlutterFragmentActivity
|
||||
|
||||
class MainActivity : FlutterFragmentActivity()
|
||||
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 8.9 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 69 B |
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:gravity="fill" android:src="@drawable/background"/>
|
||||
</item>
|
||||
<item>
|
||||
<bitmap android:gravity="center" android:src="@drawable/splash"/>
|
||||
</item>
|
||||
<item android:bottom="24dp">
|
||||
<bitmap android:gravity="bottom" android:src="@drawable/branding"/>
|
||||
</item>
|
||||
</layer-list>
|
||||
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 69 B |
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:gravity="fill" android:src="@drawable/background"/>
|
||||
</item>
|
||||
<item>
|
||||
<bitmap android:gravity="center" android:src="@drawable/splash"/>
|
||||
</item>
|
||||
<item android:bottom="24dp">
|
||||
<bitmap android:gravity="bottom" android:src="@drawable/branding"/>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/mih_icon_background" />
|
||||
<!-- <size android:width="48dp" android:height="48dp"/> -->
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:drawable="@drawable/calculator"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:gravity="center" />
|
||||
</layer-list>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/mih_icon_background" />
|
||||
<!-- <size android:width="48dp" android:height="48dp"/> -->
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:drawable="@drawable/mih_logo"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:gravity="center" />
|
||||
</layer-list>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/mih_icon_background" />
|
||||
<!-- <size android:width="48dp" android:height="48dp"/> -->
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:drawable="@drawable/mzansi_ai"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:gravity="center" />
|
||||
</layer-list>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/mih_icon_background" />
|
||||
<!-- <size android:width="48dp" android:height="48dp"/> -->
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:drawable="@drawable/mzansi_directory"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:gravity="center" />
|
||||
</layer-list>
|
||||