This project is a decentralized Electronic Health Record (EHR) management system built using:
- Solidity Smart Contracts
- Ethereum Blockchain
- IPFS (InterPlanetary File System)
- ethers.js
- MetaMask
- Angular
- Local Anvil Node
The system enables secure and decentralized management of:
- Patients
- Doctors
- Appointments
- Medical Records
- Access Permissions
The architecture follows an IPFS-first design where sensitive medical data is stored off-chain while only essential references and permissions are maintained on-chain.
The main goals of this project are:
- Eliminate centralized health record dependency
- Ensure tamper-resistant medical history
- Enable decentralized ownership of health records
- Provide secure doctor-patient access control
- Reduce data duplication and unauthorized access
- Learn Web3-based healthcare architecture
| Technology | Purpose |
|---|---|
| Solidity | Smart Contract Development |
| Ethereum | Blockchain Network |
| Anvil | Local Ethereum Development Node |
| Hardhat | Smart Contract Tooling |
| ethers.js | Blockchain Interaction |
| MetaMask | Wallet Authentication |
| IPFS | Decentralized File Storage |
| Angular | Frontend Application |
| TypeScript | Frontend Logic |
The blockchain stores:
- Wallet addresses
- User roles
- Appointment references
- Medical record references
- Access permissions
- IPFS content identifiers (CIDs)
IPFS stores:
- Patient profile metadata
- Doctor profile metadata
- Appointment metadata
- Medical record metadata
- Uploaded medical files/documents
Responsible for:
- Registering doctors
- Registering patients
Can:
- View authorized patient records
- Add medical records
- Approve/reject appointments
- View appointments
Can:
- Book appointments
- Grant/revoke doctor access
- View own medical records
- Cancel appointments
- Register doctors
- Register patients
- Validate user roles
struct User {
address id;
string profileCID;
bool exists;
}- Book appointments
- Update appointment status
- View appointments by user
- Admin can view all appointments
- PENDING
- APPROVED
- REJECTED
- COMPLETED
- CANCELED
struct Appointment {
uint256 id;
address patient;
address doctor;
string metadataCID;
uint256 appointmentTime;
AppointmentStatus status;
uint256 createdAt;
}- Upload medical records
- Retrieve patient records
- Access-controlled record viewing
struct MedicalRecord {
uint256 id;
address patient;
address doctor;
string metadataCID;
string filesCID;
uint256 createdAt;
}Patients can:
- Grant doctors access to records
- Revoke doctor access
Doctors can:
- Access records only when permission is granted
mapping(address => mapping(address => bool))
private doctorAccess;Sensitive data is NOT stored directly on-chain.
Only:
- references
- permissions
- relationships
- metadata CIDs
are stored on blockchain.
Appointments and records are stored using:
mapping(uint256 => Appointment)
mapping(uint256 => MedicalRecord)with indexed relationships for scalability.
Medical records are accessible only if:
- requester is the patient
- requester is an authorized doctor
- Admin registers patient
- Patient profile uploaded to IPFS
- CID stored on blockchain
- Admin registers doctor
- Doctor profile uploaded to IPFS
- CID stored on blockchain
- Patient selects doctor
- Appointment metadata uploaded to IPFS
- Appointment stored on blockchain
- Doctor receives permission
- Medical files uploaded to IPFS
- CID references stored on blockchain
- Role-based access control
- Permission-controlled medical records
- Immutable blockchain records
- Decentralized storage
- Patient-controlled authorization
- Decentralized architecture
- Improved transparency
- Tamper resistance
- Reduced centralized dependency
- Better interoperability
- Patient ownership of data
- Blockchain transaction costs
- Public blockchain metadata visibility
- IPFS availability management
- No encryption implemented in MVP
- Limited scalability without indexing
- Encrypted IPFS payloads
- Hospital management module
- Prescription management
- Pagination support
- Event indexing
- Audit logs
- Multi-admin support
- The Graph integration
- Role-based dashboards
- JWT + Web3 hybrid auth
- File encryption and key management
Run:
./start-project.shThis starts:
- Local Anvil blockchain
- Local IPFS node
- Frontend application
- Required development services
Run:
./deployer.shnpx hardhat compilenpx hardhat ignition deploy ignition/modules/EHR.ts --network localhostInstall dependencies:
npm installRun Angular frontend:
ng servecontracts/
├── EHR.sol
frontend/
├── src/
ignition/
├── modules/
│ └── EHR.ts
scripts/
├── deployer.sh
├── start-project.sh
This project demonstrates a decentralized healthcare record management system using blockchain and IPFS technologies. The architecture prioritizes:
- decentralized ownership
- secure access control
- scalable smart contract design
- minimal on-chain storage
The implementation serves as a strong MVP foundation for future enterprise-grade decentralized healthcare applications.