I am working on an application that can handle SQL queries for data stored in Blockchain. Currently I am using Smart Contract for achieving this as this allows me to store the data in a well structured form. To be more specific I am working on providing SQL queries in the healthcare sector. Though the actual EHR document continues to remain in some decentralized file system like IPFS but for me to be able to query using SQL I have stored few metadata information using Smart Contract using data types like struct and mapping. I know storing data in Blockchain is an expensive task but for me to be able to query things I need to have metadata(atleast) to be stored in Blockchain. I haven't explored web3 library much but I'm just aware that using web3 we may be able to see only details such as block number, block hash, previous block hash etc. but not my custom data such as patient name, symptoms etc. Does this idea of querying Blockchain using Smart Contract sound fair? Any pointers if this can be achieved in some other more efficient way both in terms of cost or throughput?
3 Answers
Using IPFS and blockchain to store medical data sounds like a dangerous idea. Because all of the patient's data will be publicly viewable.🤔
Technically you can just store the records in a smart contract using a "write function" and read the stored data from a smart contract using the "read function".
For example.
You don't have to pay anything to retrieve the data but updating/creating new records requires gas. Hope that helps.
Best not to store personal information directly to any public viewable shared network. You could put hashed metadata on it, but that will still be viewable by the public.
Do note that IPFS does not guarantee the file will always be there. So you could store data and it can go missing once there is no node sharing it anymore. So only if the linked organisation is also a IPFS node and always keeps the data, the data would also be there. I just guess that is not the reason why you would want this data on the blockchain.
Do check other options like ceramic and soulbound tokens.
-
No, blockchain will be used just for storing necessary metadata information using Smart Contracts so that SQL querying ability can be achieved also at the same time cutting down the cost to some extent by storing the actual medical record in IPFS. Definitely the document CID is one of the metadata. If IPFS data has that chance of being unavailable, then yeah, I'll look into the options that you suggested. Thanks. Feb 9 at 6:41
The NFT marketplace like Opensea have separate database that stores the nft data and retrieve from the database when user requests the data. So they are not querying blockchain but their database or using API's (Moralis). So upload confidential data to distributed storage and get the hash and upload it to blockchain with input values(patient name, symptoms). We can't search the blockchain with input values. So, while uploading to blockchain upload the same to database and query from database. And about soul bound tokens its good to use in medical field like vaccination certificate as non transferable NFT, but in your application its of no use. And for storing files try Stroj it has default encryption and a part of chunks is enough to retrieve the data.