- Backend
- Blockchain
- SmartContract
- HL7Convertor
- Docker
The backend is written in Python, using the FastAPI framework. When getting run, the Python backend tries to access the local Ethereum blockchain network ad 127.0.0.1:9545.
Moreover, It has 5 endpoints:
HTTP | Purpose |
---|---|
POST /record/set | Create a new record on the blockchain |
GET /record/get/:key | Get records of the blockchain, based on the provided publickey |
POST /thirdparty/add | Create a thirdparty, for the provided publickey |
GET /thirdparty/get/:key | Get a public key’s thirdparties |
GET /blockchain/publickey | Get blockchain public key |
Generate a based on the provided public key, and store the value for the generated key.
Given that the provided publickey is FOO, based on the provided publickey, the generated key will be:
FOO||||FOO
“||||” (four pipes) is the delimiter.
[PATIENT PUBLIC KEY] + delimiter + [PATIENT PUBLIC KEY]
[BLOCKCHAIN PUBLIC KEY] + delimiter + [PATIENT PUBLIC KEY]
Each time a value gets created on the blockchain, an identical record with the same value will be created with a different key. This means a new record with a value X will have the following format:
{
…
“FOO||||Foo”: [..., X],
“BLOCKCHAIN_PUBLICK_KEY||||Foo”: [..., X],
…
}
You will get a list of all the data the provided public key has on the blockchain.
Each public key in the blockchain will have a list indicating who has been granted to see what data. By removing or adding thirdparties, we store a new copy of the current valid thirdparties. With having their state, we can tell, for example:
“Mr. Brown(a thirdparty) has been on the list of Miss Blue*(the patient)*’s thirdparities for 2 years, however, Mr. Brown is no longer considered a thirdparty as Miss Blue removed him 2 months ago”
Simply a list containing all thirdparties in a list of public keys.
This is the structure for the data we store on the blockchain for the access list (thirdparties):
[BLOCKCHAIN PUBLIC KEY] + delimiter + [PATIENT PUBLIC KEY] + delimiter + access_list + delimiter + index
BLOCKCHAIN_PUBLICK_KEY||||FOO||||acess_list|||0
BLOCKCHAIN_PUBLICK_KEY||||FOO||||acess_list|||1
BLOCKCHAIN_PUBLICK_KEY||||FOO||||acess_list|||2
BLOCKCHAIN_PUBLICK_KEY||||FOO||||acess_list|||3
BLOCKCHAIN_PUBLICK_KEY||||FOO||||acess_list|||4
By keeping old states, we have access to historical data of the changed states.
We use Truffle suit for the sake of the local Ethereum network.
The network will be available at 127.0.0.1:9545
Blockchain will take the responsibility of deploying the smart contract on the network and migrating it.
The solidity smart contract is the actual core of the functionality we do on the blockchain network.
The smart contract can be found at blockchain/contracts/SimpleStorage.sol
It has 5 methods on it:
- setData(string memory key, string memory encryptedString)
- getData(string memory key)
- increaseAccessListState(string memory key)
- getAccessListState(string memory key)
- addNewThirdparty(string memory newAccessKey, string memory oldAccessKey, string memory newPublicKey)
Also, it has 2 global variables:
- mapping(string => string[][]) public dataMap;
- mapping(string => int) public accessListStateMap;
This is a backend service written in Rust using the Axum framework. The main responsibility of the hl7convertor is to transform an XML with format A to an XML with format B.
It does its job using XSLT (Extensible Stylesheet Language Transformations) to convert two XMLs back and forth.
Wikipedia
Given the following XML:
<Employee\>
<firstName\>John\</firstName\>
<lastName\>Doe\</lastName\>
</Employee\>
When XLST is:
<xsl:stylesheet version=\\"1.0\\" xmlns:xsl=\\"[http://www.w3.org/1999/XSL/Transform\\](http://www.w3.org/1999/XSL/Transform\\)"\>
<xsl:template match=\\"/\\"\>
<Person\>
<fullName\>\<xsl:value-of select=\\"concat(//firstName, ' ', //lastName)\\"/\>\</fullName\>
</Person\>
</xsl:template\>
</xsl:stylesheet\>
Then we have:
<Person\>
<fullName\>John Doe\</fullName\>
</Person\>
**You can use the above input to test to hl7convertor functionality
Docker and DockerCompose are used together to make the deployment of this stack smooth. Here I define each app and its listened ports:
Process | Port |
---|---|
Backend | 8002 |
Etheruem | 9545 |
HL7Convertor | 2000 |
When deploying using docker-compose up, after installing are requirements a bash file will be fired to run each service. It’s called entrypoint.sh
Install Just
Run just up
**For further info run just help