← All work

Home Health Agency API

A Django REST API backend for home health agency operations, with patient care, employee records, scheduling, and role-based access.

Status
Client work
Stack
  • Django
  • Django REST Framework
  • MySQL
  • JWT
  • HIPAA

Overview

The Home Health platform is a Django REST API backend. It manages the daily work of a home health agency. The work includes patient care, employee records, scheduling, clinical documentation, and billing.

The API gives one service to web and mobile clients. It keeps the data of each agency separate. A user can only see the records of their own agency.

The system uses a custom user model and JSON Web Token (JWT) authentication. It uses a profile-based permission model. Each permission connects to a role, and each role connects to a user.

The problem

A home health agency must keep many types of records. It must track patients, visits, caregivers, physicians, insurance, supplies, and clinical notes. These records are sensitive. Only approved staff can read or change them.

Separate tools make this work difficult. Staff must move between tools. Data becomes inconsistent. It is also difficult to control who can see which record.

I built one API to hold this data in one place. The API also enforces access rules at the server. The client cannot bypass these rules by hiding or changing an interface element.

Implementation

Agency and multi-tenancy

The data model starts at the agency. Most resources connect to an agency record. The URL paths include the agency, for example /agencies/{agency_pk}/patients/.

The API checks the agency of the user against the agency in the request. A user cannot read the records of another agency.

The agency module also manages branches, hospitals, pharmacies, physicians, insurance plans, and supplies.

Patients and clinical care

The clinical module organizes care around the patient and the episode. An episode connects a patient to a start date, a frequency, and a discipline.

The module also manages:

  • Patient demographics and history
  • Admission periods
  • Patient physicians and insurance
  • Medications and medication profiles
  • Goals and interventions
  • Tasks and care plans
  • Medical supplies
  • Visit schedules

The care plan library gives staff a set of goals and interventions to reuse.

Employees and human resources

The HR module stores employee records and professional profiles. It also stores notes, attachments, executive employees, team conferences, and a history of profile changes.

Scheduling

The scheduling module manages agency schedules, executive schedules, and user schedules. Each schedule connects to a visit and a caregiver.

Authentication and access control

Users sign in with a username and password. The server returns a JWT access token and a refresh token. Access tokens expire after 60 minutes by default. Refresh tokens expire after 2 days.

The permission system checks two items. First, it checks the permission code. Second, it checks the operation. The operation comes from the HTTP method:

  • GET maps to READ
  • POST maps to CREATE
  • PUT and PATCH map to UPDATE
  • DELETE maps to DELETE

A role stores a list of allowed operations. The check fails if the user does not have the correct operation for the request.

The system also limits brute-force attacks. It rate-limits the login endpoint for each IP address. It rate-limits the password-change endpoint for each user.

A password change revokes all active tokens for the user.

API response format

Every response uses one envelope. This gives clients a predictable format.

A success response has success, data, and meta. An error response has success, error, and meta. The error object contains a code, a message, and optional field details.

The error codes include VALIDATION_ERROR, PERMISSION_DENIED, NOT_FOUND, and METHOD_NOT_ALLOWED.

Audit and HIPAA safeguards

The system records each request in a rotating audit log. A record includes the user, the agency, the HTTP method, the path, the operation, the status code, and the client IP address.

The audit log does not contain request bodies, query strings, or credentials. This prevents patient data and secrets from entering the log.

The system also stores login history and application errors in separate logs.

Other safeguards include:

  • Password hashing with PBKDF2
  • Author and update fields on most records
  • A change history for notes
  • Options for TLS redirect, HSTS, and secure cookies
  • Django admin disabled by default

API documentation and test data

The project uses drf-spectacular to generate an OpenAPI schema. It serves Swagger UI at /api/docs/ and ReDoc at /api/redoc/.

The project includes fixtures for seed data. Helper scripts convert CSV data to JSON fixtures. The ICD-10 code data uses a bulk update-or-create method to load large data sets.

Tech stack

Python, Django 5.2, Django REST Framework, drf-spectacular, MySQL 8, Simple JWT, and django-cors-headers.

Outcome

The API is the backend for the Home Health platform. It provides one consistent service for agency, clinical, HR, scheduling, financial, and messaging data.

The permission system and the agency checks keep records within the correct agency. The audit log gives a record of each request without storing patient data.

The test suite covers the response envelope, agency authorization, permissions, and the main application modules.

What I learned

Access control is easier to verify when it is part of the server code. The client must not decide who can read or change a record.

Multi-tenancy needs a clear rule. In this project, the agency is the boundary of the data. When the rule is clear, each endpoint can apply it in the same way.

Audit logs are useful only when they are safe. It is important to record who did what, but it is also important to keep patient data and secrets out of the log.

I also learned that a shared response format makes client work simpler. The client can handle success and error cases in one place.