Skip to content

API for clinic logistic. CRUD for patients, professionals and secretaries/admin, appointments schedule and queue management. Appointments messages by email and whatsapp.

Notifications You must be signed in to change notification settings

AndreKuratomi/kenzie_doc_django

Repository files navigation

kenzie_doc_django


Translations


About

The API kenzie_doc_django was made for a clinic logistic. It makes CRUD operations for patients, physicians and secretaries (admins), creates and manages appointments in a simple and intuitive way, as well as manages the waiting queue of the day.

This API also gives the user the possibility to look for professionals by its specialty and also to schedule appointments with the professional chosen in a very simple way.

After the appointment is scheduled, an email is automatically sent for both patient and professional. They are also warned by email if the appointment is updated, finished or canceled. The very same for whatsapp messages.

It uses the language Python, its framework Django and the database SQLite3. For sending emails it uses Django's sendmail and for whatsapp messages the PyWhatKit lib.


Diagram

diagram of table relationships

kenzie_doc_django API diagram

Description

Bellow a brief description of each table listed above, their permissions and their endpoints:

Due to the context that this API works with 3 different types of users that log the API and may perform some specific operations it was decided to work with customized User models. The user models are 'User', 'Patient', 'Professional' and 'Admin':

User

Model

The User model could be descripted as the API's meta user. For this API it was developed to be the table that has the fields that all the other user models have in common. These other user models have OneToOne relationship with it.

This model also has a relationship OneToMany with the Address model that is going to be treated afterwards.

The user table doesn't have its own views and endpoints.


Patient

Model

The patient model has OneToOne relationship the model User and is defined of having both 'is_admin' and 'is_prof' fields set to False in the related User model. Its specific field is the 'register_number', a random string with 6 letters, one hyphen and 1 number (e.g.: 'ZxcVaS-2') and generated after its registration.

Views and permissions

PatientsView: class view for patient register (POST) and list of all patients (GET).
Permissions: every logged and not logged user may be registered as patient, but only admins can list all patients.

PatientByIdView: class view for own patient list (GET), update (PATCH) and deletion (DELETE).
Permissions: every logged admin and the own patient may list and update some fields of its own data, but only admins can delete it.

Endpoints

patient/
patient/<str:register_number>/
Obs: for this version the register_number is case-sensitive.

Professional

Model

The professional model has OneToOne relationship the model User and is defined of having only 'is_prof' field set to True in the related User model. Its specific fields are:

1. the 'council_number', a string with 4 digits, one hyphen and 2 letters generated by the professional's address' postcode (see bellow) and
2. his 'specialty'.

Views and permissions

ProfessionalsView: class view for professional register (POST) and list of all professionals (GET).
Permissions: only logged admins may register and list professionals.

ProfessionalByIdView: class view for list (GET), update (PATCH) and deletion (DELETE) of a professional by its council_number.
Permissions: every logged admin and the own professional may list and update some fields of its own data, but only admins can delete it.
Obs: if the permited user updates the address to a different state the professionals' council_number's final two digits are automatically updated.

ProfessionalBySpecialtyView: class view for listing all professionals registered by their specialty.
Permissions: every logged user may list it.

Endpoints

professional/:
professional/&ltstr:council_number&gt/: -> The API will turn the council_number typed automatically to uppercase.
professional/specialty/&ltstr:specialty&gt/: -> The API will capitalize the specialty typed automatically.


Admin

Model

The admin (secretary) model has OneToOne relationship the model User and is defined of having only 'is_admin' field set to True. It has no specific field.

Views and permissions

AdminView: class view for professional register (POST) and list of all professionals (GET).
Permissions: only logged admins may list all admins.

Endpoints

admin/

Address

Model

The address model has OneToMany relationship the model User. It has just two compulsory fields to be filled: house_number and post_code.

This model uses the brazilian lib brazilcep that provides the other optional fields 'street', 'city', 'state' if the postcode is given. This lib is used both for the user address registration and also for the professional's council_number:

E.G.: if the admin types '9876' for the professional's council_number and types '20031-170' for the postcode the response will be '9876-RJ'.

As well as the user table, the address one also doesn't have its own views and endpoints.


Appointments

Model

The appointment model has relationship ManyToOne with both Patients and Professionals. Both users may have various appointments but each one has only one patient with one professional.

Views and permissions

CreateAppointment: class view for appointment schedule (POST).
Permissions: Only admins may schedule an appointment.

SpecificAppointmentView: class view for listing, updating and deleting an appointment by its IB.
Permissions: Only admins may may perform in this view.

SpecificPatientView: class view for the patient's appointments list (GET).
Permissions: Only the own patient or admins may list his appointments.

SpecificProfessionalView: class view for the professional's appointments list (GET).
Permissions: Only the own professionl or admins may list his appointments.

ProfessionalAppointmentsTodayView: class view for the professional's open appointments of the current day.
Permissions: Only admins may list the professional's open appointments of the day.

NotFinishedAppointmentsView: class view for the waiting queue of the day by professional. It is returned a message like this: .

    "msg": "There are 2 patients waiting for their appointments with Dr. Jefferson today. The average waiting time is ca 2 hours and 0 minutes"

Permissions: Only admins may list the professional's not finished appointments.

FinishAppointmentView: class view for finishing a specific appointment by its ID (PATCH).
Permissions: Only admins may finish an appointment.

Obs: All view operations for POST, PATCH and DELETE have notifications configured to be sent for the patient's and professional's email and whatsapp number.

Endpoints

appointments/:
appointments/professional/<str:council_number>/:
appointments/<str:appointment_id>/:
appointment_finish/<str:appointment_id>/:
appointments/patient/<str:register_number>/:
appointments/open_24/<str:council_number>/:
appointments/open/<str:council_number>/:

Instalation

0. It is first necessary to have instaled the following devices:

  • The code versioning Git.

  • A code editor, also known as IDE. For instance, Visual Studio Code (VSCode).

  • The programming language Python.

  • A client API REST program. Insomnia or Postman, for instance.

  • And versioning your directory to receive the aplication clone:

git init

1. Clone the repository kenzie_doc_django by your machine terminal or by the IDE's:

git clone https://github.com/AndreKuratomi/kenzie_doc_django.git

WINDOWS:

Obs: In case of any mistake similar to this one:

unable to access 'https://github.com/AndreKuratomi/kenzie_doc_django.git/': SSL certificate problem: self-signed certificate in certificate chain

Configure git to disable SSL certification:

git config --global http.sslVerify "false"

Enter the directory:

cd kenzie_doc_django

2. After cloning the repository install:

Virtual enviroment* and update its dependencies with the following command:

LINUX:

python3 -m venv venv --upgrade-deps

WINDOWS:

py -m venv venv --upgrade-deps

In case an error like this one is returned just follow the command displayed:

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

*It is a good practice to work with virtual enviroments because different projects may need different dependencies. A virtual enviroment is only a separated enviroment from the user machine. If not used, the user's machine may have lots of dependencies intalled that may only be used in a single project.

Ativate your virtual enviroment with the command:

LINUX:

source venv/bin/activate

WINDOWS:

On Windows operational system it is necessary to configure the Execution Policy at PowerShell:

Get-ExecutionPolicy # to check the Execution policy type
Set-ExecutionPolicy RemoteSigned # to change the type of policy if the command above shows 'Restricted'

Obs: It may often be necessary to open PowerShell as administrador for that.

.\env\Scripts\activate

Install its dependencies:

pip install -r requirements.txt

WINDOWS:

In case any error similar to the one bellow be returned:

ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\andre.kuratomi\\OneDrive - Company\\Área de Trabalho\\kenzie_doc_django\\kenzie_doc_django\\env\\Lib\\site-packages\\jedi\\third_party\\django-stubs\\django-stubs\\contrib\\contenttypes\\management\\commands\\remove_stale_contenttypes.pyi'
HINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths

Run cmd as adminstrador with the following command:

reg.exe add HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f

3. Open the aplication with your IDE:

code .

4. Create .env file:

./

touch .env

Inside it we need to put our enviroment variables taking as reference the given file .env.example:

# DJANGO:
SECRET_KEY=secret_key

# EMAIL VARIABLES:
EMAIL_HOST_USER=host_email
EMAIL_HOST_PASSWORD=host_password

Obs: Do not share info from .env file. It is already mentioned in .gitignore for not being pushed to the repo.


5. And run django:

LINUX:

python manage.py runserver

or

./manage.py runserver

WINDOWS:

py manage.py runserver

Documentation

For full description of endpoints and its responses check the insomnia documentation on the link bellow (necessary free login account) click here.


API developers

Pierre Kalil - Techlead


Leonardo Pereira - Product Owner


André Kuratomi - Scrum Master


Keila Passos - Developer


Kaio Iwakiri - Developer


References


Terms of use

This project is exclusively for didatic purposes and has no commercial intent.

About

API for clinic logistic. CRUD for patients, professionals and secretaries/admin, appointments schedule and queue management. Appointments messages by email and whatsapp.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages