Medera - Backend Service for the Hedera Hackathon
This repository contains the backend service for the Medera project, a healthcare solution built using the Hedera Hashgraph platform. The application is developed using NestJS, providing a scalable, efficient, and modular backend framework.
Medera aims to revolutionize healthcare by leveraging the power of distributed ledger technology (DLT). Using the Hedera network, we ensure secure, transparent, and decentralized healthcare solutions.
This project was built for the Hedera Hackathon, showcasing the integration of cutting-edge technologies for a transformative healthcare application.
- DLT Integration: Secure and transparent data storage on Hedera.
- Modular Architecture: Built with NestJS for maintainability and scalability.
- API-First Approach: Provides robust and documented RESTful APIs.
- Enhanced Security: Uses Hedera for tamper-proof data integrity.
Before running the project, ensure you have the following installed:
- Node.js (v18.x or higher)
- npm or yarn
- A Hedera testnet/mainnet account (Get one here)
-
Clone the repository:
git clone https://github.com/GHkrishna/medera-backend.git cd medera-backend
-
Install dependencies:
yarn install
-
Run the application:
yarn start
-
For development mode with hot-reloading:
yarn start:dev
Create a .env
file in the root directory and add the following variables:
# Agent Configuration
AgentLabel=medera
AgentWalletID=medera
AgentWalletKey=medera
AGENT_PROTOCOL=http
AGENT_ENDPOINT=http://ip-address:3000
SHORT_URL_DOMAIN=http://ip-address:3000
# Doctor Tenant and Schema
DOCTOR_TENANT_ID=
DOCTOR_DID=
PRESCRIPTION_SCHEMA=https://ghkrishna.github.io/schemas/Prescription.json
# Connect to a local postgres instance or neon db(https://neon.tech):
NEON_DB_PASS=postgres
NEON_DB=medera
NEON_DB_ROLE=postgres
NEON_DB_URL=postgresql://postgres:postgres@localhost:5432/medera
NEON_DB_HOST=localhost:5432
# Pharmacy Configuration
PHARMACY_RECEIPT_SCHEMA=https://ghkrishna.github.io/schemas/PharmacyReceipt.json
PRARMACY_TENANT_ID=
PHARMACY_DID=
# Hedera Account
PRIVATE_KEY=
ACCOUNT_ID=
Replace placeholders with the respective values:
- Hedera credentials:
PRIVATE_KEY
andACCOUNT_ID
. - Database details:
NEON_DB_PASS
,NEON_DB_ROLE
, andNEON_DB_URL
. - Tenant-specific IDs:
DOCTOR_TENANT_ID
,PHARMACY_TENANT_ID
, andDOCTOR_DID
.
Start the application initially without tenant id and DIDs. Howver, Agent details, database details and hedera account(of type ED25519
) details created from Hedera portal are required.
Note: eventhough the variable details are
NEON_DB
specific you can connect to any postgress instance
- Start postgres locally
- Now, enter the appropriated details in the
.env
for your db
Note: In case you are connecting to a hosted DB, you'll need to create a wallet for your tenant by adding the following code in your ./src/agent/agent.ts
before await agent.initialize()
// Add this before await agent.initialize();
await agent.wallet.create({
id: process.env.AgentWalletID,
key: process.env.AgentWalletKey,
storage: {
type: 'postgres',
config: {
host: process.env.NEON_DB_HOST,
connectTimeout: 10,
maxConnections: 1000,
idleTimeout: 30000,
},
credentials: {
account: process.env.NEON_DB_ROLE,
password: process.env.NEON_DB_PASS,
adminAccount: process.env.NEON_DB_ROLE,
adminPassword: process.env.NEON_DB_PASS,
},
},
});
await agent.initialize();
To set the tenant id,
- Start the application initially without tenant id
- Headover to the hosted application (http://localhost:3000) and create a tenant using the /agent/createTenant
- Not you will need to create two tenants for Doctor and Pharmacy. After creating the tenant add them to their respective
env
variables
The application intends to support did creation on hedera:testnet. To create a did:hedera:testnet
follow the following steps.
Note: We will create a
did:hedera:testnet
for both Doctor and Pharmacy. However we won't be including them into theenv
directly(This is due to an issue with difference in resolving & signing of a created and imported DID). Instead we'll be creating a DID for each tenant and them import the created DID into alternative agents. So in our case, the doctor(tenant) will create a did, which will then be imported by the pharmacy(tenant) and vice versa.
- Create a DID as a doctor(tenant-id) from the endpoint /agent/createHederaDid
- Once a DID is created, copy the seed used and created did received from response. Now we will import this DID into the Pharmacy tenant/wallet
Note: The seed must be unique 32 characters for each new DID creation
- Import the did into pharmacy(tenant-id) from endpoint /importHederaDid
- Once import is successful with statusCode
201
. You can save this DID into thePHARMACY_DID
- We will once again repeat the same process to get a DID for Doctor.
Note: In this case the Pharmacy will create the did and the doctor will import it. Once this is completed we will have the value for
DOCTOR_DID
Now that you have all the details required to start, you can restart your service with the updated .env
.
The API endpoints are documented using Swagger.
- Start the application.
- Navigate to the API docs at:
http://localhost:3000/api
Note: To ensure the demo works seamlessly, head over to the backend (http://your-ip:port/api#/) and ensure the application is up and running by observing the response for these three endpoints /agent/agentDetails(http://localhost:3000/api#/agent), /doctor/agentDetails and(http://localhost:3000/api#/doctor) /pharmacy/agentDetails(http://localhost:3000/api#/pharmacy) to ensure the backend is brought into cache by the hosting provider
Explore and test the endpoints directly from the Swagger UI.
medera-backend/
├── src/
│ ├── modules/ # Feature-based modules
│ ├── controllers/ # API controllers
│ ├── services/ # Business logic
│ ├── entities/ # Database entities (if applicable)
│ ├── utils/ # Utility functions
│ ├── main.ts # Entry point of the application
├── test/ # Unit and integration tests
├── .env # Environment configuration
├── package.json # Dependencies and scripts
└── README.md # Project documentation
We welcome contributions! To contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add new feature"
- Push to your branch:
git push origin feature-name
- Submit a pull request.
- Hedera: For providing a secure and efficient DLT platform.
- NestJS: For the robust backend framework.
- Hackathon Team: Sai Ranjit, Tipu Singh, Pranali Dhanavade
Project Links:
- Frontend Repo Clinic - Frontend Clinic Live Demo
- Frontend Repo Pharmacy - Frontend Pharmacy Live Demo
- Backend Live Demo
Note: To ensure the demo works seamlessly, head over to the hosted backend and ensure the application is up and running by observing the response for these three endpoints /agent/agentDetails, /doctor/agentDetails and /pharmacy/agentDetails to ensure the backend is brought into cache by the hosting provider
Contact:
For queries or support, reach out to us at: [waskekrishna@gmail.com]