You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
nochill ceb456041b
update readme
6 months ago
api_collection update readme 6 months ago
app update readme 6 months ago
migrations Update encounter handling and is_deleted 6 months ago
.env.example updage env example 6 months ago
.gitignore init 6 months ago
.pre-commit-config.yaml init 6 months ago
README.md update readme 6 months ago
alembic.ini init 6 months ago
api_collection_postman.json update readme 6 months ago
poetry.lock add patient, encounters, doctors, schedule, clinics 6 months ago
pyproject.toml add patient, encounters, doctors, schedule, clinics 6 months ago
test2.py update test2 solution 6 months ago

README.md

Table of Contents
  1. Getting Started
  2. Usage
  3. Api collection
  4. 2nd test

Getting Started

Schema

image

Installation

  1. Clone the repo
    git clone https://git.nochill.in/nochill/fastapi_health
    
  2. (Optional) create new virtual environment and use the virtual environment
    python3 -m venv venv
    ### done creating venv
    source venv/bin/activate
    
  3. install poetry
     pip install poetry
    
  4. install the dependencies
    poetry install
    
    • if you got an error, propbably the pyprject.toml python version is not match, update the version in pyproject.toml, then adjust with your python version
      [tool.poetry.dependencies]
      python = "^3.10" # adjust with your machine python version
      ....
      [tool.mypy]
      python_version = "3.10" # adjust with your machine python version
      strict = true
      
  5. copy .env.example as .env, then fill .env with your system configuration
    cp .env.example .env
    
    # .env example
    SECURITY__JWT_SECRET_KEY=DVnFmhwvjEhJZpuhndxjhlezxQPJmBIIkMDEmFREWQADPcUnrG # random string
    SECURITY__BACKEND_CORS_ORIGINS=["http://localhost:3000","http://localhost:8001"]
    SECURITY__ALLOWED_HOSTS=["localhost", "127.0.0.1"]
    
    DATABASE__HOSTNAME=localhost
    DATABASE__USERNAME=example
    DATABASE__PASSWORD=example
    DATABASE__PORT=5432
    DATABASE__DB=example_db
    
  6. run the migration
    alembic upgrade head
    
  7. run the app
    uvicorn app.main:app
    

Usage

Authentication

POST /auth/register create new user
Body
name type data type description
name required string N/A
password required string N/A
Responses
http code content-type response
201 application/json {"id": 1, "username": "halo"}
500 application/json {"detail":"something went wrong"}
POST /auth/login login
Body
name type data type description
name required string N/A
password required string N/A
Responses
http code content-type response
201 application/json {"id": 1, "username": "halo", "token" : "", "expiers_at": ""}
500 application/json {"detail":"something went wrong"}

Bearer Authentication

From here every request need Bearer Token
Header
name type data type description
Authorization string string Bearer {token}
Responses
http code content-type response
401 application/json {"detail": "Authorization Header Missing}

PATIENT

POST /patients Create new patient
Body
name type data type description
name required string N/A
Responses
http code content-type response
200 application/json {"id": 1, "name": ""}
500 application/json {"detail": "Something went wrong"}
GET /patients get new doctors
Body
name type data type description
name required string N/A
Responses
http code content-type response
200 application/json {"id": 1, "name": ""}
500 application/json {"detail": "Something went wrong"}

Doctor

POST /doctors Create doctor
Body
name type data type description
name required string N/A
clinic_id required int N/A
Responses
http code content-type response
201 application/json {"id": 1, "name": "", "clinic_id": ""}
500 application/json {"detail": "Something went wrong"}
GET /doctors get doctors
Parameters
name type data type description
clinic_id required int N/A
limit optional int Total data (default = 10)
offset optional int Starting point of query result (default = 0)
Responses
http code content-type response
200 application/json {"count": 12, "data": []}
500 application/json {"code":"400","message":"Bad Request"}
PATCH /doctors/{doctor_id} update doctor
Parameters
name type data type description
name required string N/A
clinic_id optional int N/A
Responses
http code content-type response
200 application/json {"id": 1, "name": , "clinic_id": }
400 application/json {"detail": "Cant change doctor clinic, doctor still have encounter with this clinic id"}
500 application/json {"code":"400","message":"Bad Request"}

Doctor Schedule

POST /schedule/doctor create doctor schedule
Body
name type data type description
day required string day name contain with values one of ["senin,"selasa,"rabu,"kamis,"jumat,"sabtu,"minggu"]
time_start required string time format 24h "08:00", "23:00"
time_end required string time format 24h "08:00", "23:00"
quota required int total quota
doctor_id required int N/A
clinic_id required int N/A
Responses
http code content-type response
200 application/json {"id": 1, "day": "senin", "time_start": "08:00:00", "time_end": "22:00:00}
500 application/json {"detail": "Something went wrong"}
GET /schedule/clinic/{clinic_id} get all doctors schedule from clinics
Parameters
name type data type description
doctor_id Optional int get schedule from specific doctor
limit Optional int default(10)
offset Optional int default(0)
Responses
http code content-type response
200 application/json {"count": 2, "data": []}
500 application/json {"detail": "Something went wrong"}

Encounter

POST /encounter create encounter / reservation
Body
name type data type description
doctor_id required int N/A
clinic_id required int N/A
patient_id required int N/A
doctor_schedule_id required int N/A
encounter_date required string format YYYY-mm-dd ex: "2024-04-28"
Responses
http code content-type response
200 application/json {"id": 1, ...}
500 application/json {"detail": "Something went wrong"}
PATCH /encounter/delay/{encounter_id} Delay queue an ecounter
Parameters

NONE

Responses
http code content-type response
200 application/json {"id": 2, "queue": 2.125, "queue code": "AO 25", ..}"
500 application/json {"detail": "Something went wrong"}
PATCH /encounter/done/{encounter_id} done queue an ecounter
Parameters

NONE

Responses
http code content-type response
204 application/json ""
400 application/json {"detail": "Encounter with id 1 not found"
500 application/json {"detail": "Something went wrong"}
PATCH /encounter/cancel/{encounter_id} cancel an ecounter
Parameters

NONE

Responses
http code content-type response
204 application/json ""
400 application/json {"detail": "Encounter with id 1 not found"
500 application/json {"detail": "Something went wrong"}
GET /encounter/{clinic_id} get list of encounters from a clinic
Parameters
name type data type description
limit Optional int default(10)
offset Optional int default(0)
Responses
http code content-type response
200 application/json {"count": 2, data:[]"
500 application/json {"detail": "Something went wrong"}

(back to top)

API COLLECTION

BRUNO

If you happen to use Bruno, you can import the collection from /api_collection folder

  • (Optional) Create Environment in bruno

gif

POSTAMN

If you happen to use Postman, you can import the collection from ./api_collection_postman.json file

2nd TEST

for the 2nd test, run with

python test2.py
def sequence_exists(main, seq):
    if len(seq) == 0:
        return True
    
    left = 0
    right = 0
    
    while right < len(main):
        if main[right] == seq[left]:
            left += 1  
            if left == len(seq):
                return True  
        else:
            left = 0 
            if main[right] == seq[left]:
                left += 1 

        right += 1  

    return False  

main = [20, 7, 8, 10, 2, 5, 6]
assert(sequence_exists(main, [7, 8])) == True 
assert(sequence_exists(main, [8, 7])) == False 
assert(sequence_exists(main, [5, 6])) == True