-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code for basic API get and edit operations
- Loading branch information
Showing
15 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PYTHONPATH=./api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__pycache__/ | ||
*.pyc | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM ubuntu:20.04 | ||
RUN apt update | ||
RUN apt install -y software-properties-common && \ | ||
rm -rf /var/lib/apt/lists/* | ||
RUN add-apt-repository ppa:deadsnakes/ppa | ||
RUN apt install -y python3.8 python3-pip | ||
|
||
WORKDIR /api | ||
|
||
COPY requirements.txt . | ||
RUN pip3 install --upgrade pip | ||
RUN pip3 install --no-cache-dir -r requirements.txt | ||
|
||
VOLUME /api | ||
VOLUME /smart-contracts | ||
|
||
ADD /api /api | ||
ADD /smart-contracts /smart-contracts | ||
|
||
RUN add-apt-repository ppa:ethereum/ethereum | ||
RUN apt-get update | ||
RUN apt-get install -y solc | ||
RUN pip3 install py-solc-x | ||
WORKDIR /smart-contracts | ||
#RUN python3.8 deploy.py | ||
WORKDIR /api |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from motor.motor_asyncio import AsyncIOMotorClient | ||
from .utils import load_config | ||
|
||
|
||
CONF = load_config() | ||
|
||
############### MONGO DATABASE #################### | ||
|
||
DB_CLIENT = AsyncIOMotorClient( | ||
host=CONF.get("databases")["default"]["HOST"], | ||
port=int(CONF.get("databases")["default"]["PORT"]), | ||
username=CONF.get("databases")["default"]["USER"], | ||
password=CONF.get("databases")["default"]["PASSWORD"], | ||
) | ||
|
||
DB = DB_CLIENT[CONF.get("databases")["default"]["NAME"]] | ||
|
||
def close_db_client(): | ||
DB_CLIENT.close() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
fastapi: | ||
debug: true | ||
|
||
databases: | ||
default: | ||
ENGINE: 'mongodb' | ||
DRIVER: 'motor' | ||
NAME: 'blockchain_med_integrity_db' | ||
USER: 'lupin' | ||
PASSWORD: 'BNPH.9z5g^8z6Pr4' | ||
HOST: 'blockchain-med-integrity-db' | ||
PORT: '27019' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_FILE = 'config/config.yml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .constants import CONFIG_FILE | ||
import yaml | ||
|
||
def load_config() -> dict: | ||
with open(CONFIG_FILE) as yaml_file: | ||
conf = yaml.load(yaml_file.read(), Loader=yaml.SafeLoader) | ||
return conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from fastapi import FastAPI | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from config import config | ||
from patients.routes import patients_router | ||
from web3 import Web3 | ||
#from utils.contract import MedDataIntegrityContractBridge | ||
|
||
|
||
#w3 = Web3(Web3.HTTPProvider("http://172.17.0.1:7545")) | ||
#w3.eth.defaultAccount = w3.eth.accounts[0] | ||
|
||
#med_data_integrity_contract_bridge = ChainVoteContractBridge(w3) | ||
|
||
app = FastAPI() | ||
|
||
origins = [ | ||
"http://0.0.0.0" | ||
] | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=["*"], | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
app.include_router( | ||
patients_router, | ||
prefix="/med-data-integrity-api/patients", | ||
tags=["patients"], | ||
responses={404: {"description": "Not found"}}, | ||
) | ||
|
||
|
||
@app.on_event("startup") | ||
async def app_startup(): | ||
""" | ||
App initialization. | ||
""" | ||
print("App has started ...") | ||
|
||
|
||
@app.on_event("shutdown") | ||
async def app_shutdown(): | ||
""" | ||
App termination. | ||
""" | ||
print( "App termination ...") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from fastapi import APIRouter | ||
from bson.objectid import ObjectId | ||
import bcrypt | ||
from config.config import DB | ||
from utils import * | ||
import main | ||
|
||
patients_router = APIRouter() | ||
patients = DB.patients | ||
|
||
@patients_router.put("/edit") | ||
async def edit_patient(data: dict): | ||
patient_id = ObjectId(data.get("id")) | ||
patient = await patients.find_one({"_id": patient_id}) | ||
if patient: | ||
result = await patients.update_one( | ||
{ | ||
"_id": patient_id | ||
}, | ||
{ | ||
"$set": { | ||
"patient_details": data.get("core_data") | ||
} | ||
} | ||
) | ||
if result.modified_count > 0: | ||
return { | ||
"status_code": 2000, | ||
"detail": "Patient information is successfully modified" | ||
} | ||
else: | ||
return { | ||
"status_code": 1001, | ||
"detail": "An error occurred while modifying patient information" | ||
} | ||
else: | ||
return { | ||
"status_code": 1000, | ||
"detail": "Failed to retrieve this patient" | ||
} | ||
|
||
|
||
@patients_router.get("/{patient_id}") | ||
async def get_patient(patient_id: str): | ||
|
||
try: | ||
patient_id = ObjectId(patient_id) | ||
patient = await patients.find_one({"_id": patient_id}) | ||
if patient: | ||
patient["_id"] = str(patient["_id"]) | ||
return { | ||
"status_code": 2000, | ||
"detail": patient | ||
} | ||
else: | ||
return { | ||
"status_code": 1001, | ||
"detail": "No patient with this id" | ||
} | ||
|
||
except Exception as e: | ||
return { | ||
"status_code": 1000, | ||
"detail": "Invalid patient id" | ||
} | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: '3' | ||
|
||
volumes: | ||
mongo_data: | ||
|
||
services: | ||
blockchain-med-integrity-api: | ||
restart: always | ||
stdin_open: true | ||
tty: true | ||
build: . | ||
command: uvicorn main:app --host 0.0.0.0 --port 7777 --debug --reload | ||
volumes: | ||
- ./api:/api | ||
- ./smart-contracts:/smart-contracts | ||
ports: | ||
- "7777:7777" | ||
depends_on: | ||
- blockchain-med-integrity-db | ||
|
||
|
||
blockchain-med-integrity-db: | ||
restart: always | ||
image: mongo | ||
command: mongod --port 27019 | ||
environment: | ||
MONGO_INITDB_ROOT_USERNAME: "lupin" | ||
MONGO_INITDB_ROOT_PASSWORD: "BNPH.9z5g^8z6Pr4" | ||
volumes: | ||
- mongo_data:/data/db | ||
ports: | ||
- "27019:27019" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fastapi[all] | ||
motor | ||
pydantic[email] | ||
bcrypt | ||
pyOpenSSL | ||
python-multipart | ||
web3 |
Empty file.
Empty file.