This project provides a RESTful API for managing healthcare patient information while adhering to FHIR standards.
- Add, retrieve, update, and delete patient records.
- FHIR-compliant data model.
- Basic token-based authentication.
- API documentation using Swagger.
- Python 3.11+
- Django 4.0+
- PostgreSQL
-
Clone the repository:
git clone https://github.com/yourusername/HealthCare_Management.git cd HealthCare_Management -
Install dependencies:
pipenv install pipenv shell
-
Set up the database:
python manage.py migrate
-
Create a superuser:
python manage.py createsuperuser
-
Collect static files:
python manage.py collectstatic
Start the development server:
python manage.py runserverThe API uses token-based authentication. To generate a token for a user:
python manage.py shellThen:
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import User
user = User.objects.get(username='your-username')
token, created = Token.objects.get_or_create(user=user)
print(f'Token for user {user.username}: {token.key}')You can also generate a token using a custom management command:
python manage.py generate_token your-username{
"token": "your-generated-token"
}- POST /fhir/Patient/: Add a new patient record.
- GET /fhir/Patient/: Retrieve a list of all patients.
- GET /fhir/Patient/{id}/: Retrieve details of a specific patient by ID.
- PUT /fhir/Patient/{id}/: Update the details of a specific patient.
- DELETE /fhir/Patient/{id}/: Delete a specific patient record.
Swagger is used for API documentation.
Run the server and navigate to:
http://127.0.0.1:8000/swagger/
To fetch the JSON documentation:
curl http://127.0.0.1:8000/swagger.json-
Build the Docker image:
docker build -t healthcare_api . -
Run the container:
docker run -p 8000:8000 healthcare_api
Ensure the following environment variables are set:
DJANGO_SECRET_KEYDATABASE_URL
You can use a .env file to manage these variables.
If the fhir.resources package is not installed via pipenv, you can install it manually:
pip install fhir.resourcesAlternatively, add it directly to your Pipfile using:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
fhir.resources = "*"Run tests using:
python manage.py test