# MedChain: Efficient Healthcare Data Sharing via Blockchain
## 3 MedChain Model
### Directory Service  
The directory service is also an important component in the MedChain model, managing the mutable information of healthcare data for data identification, location, and sharing. MedChain provides two types of directories: patient inventory and session. The mutable information and the format of directories are introduced below in detail. **Inventory**. An inventory records all the description details of a patient's healthcare data maintained by a healthcare provider. As defined in Def. (3), it includes the inventory ID (_InvID_), the inventory content (_InvContent_), and the encrypted inventory secret for healthcare providers (\(ES_{sp}\)) and patients (\(ES_{pat}\)). The inventory ID uniquely identifies the inventory with the association of the patient and the healthcare provider. For a privacy purpose, such association is obfuscated by the inventory secret \(S_{data}\). The inventory content contains a list of data descriptions, including the _DIDs_, metadata (e.g., the summary and the tags of the data), the locations of the actual data (i.e., URLs), and the references (_Ref_ or _Ref_\({}_{L}\)) to the blockchain for data integrity check. For a single record, _Ref_ refers to the location (identified by the block hash (\(BH\)) and event hash (\(EH\))) of the _Event\({}_{DG}\)_ on the blockchain. For a data stream, _Ref_\({}_{L}\) refers to the location of the last chunk _Event\({}_{DG}\)_. \[ \begin{array}{l} Inventory\langle InvID,InvContent,\ ES_{sp},ES_{pat}\rangle\\ InvIDH(PK_{user}\parallel S_{data})\\ InvContent_{ES_{data}}(\{DID,Metadata,\ URL,Ref|Ref_{L}\})\\ Ref\langle BH,EH\rangle\\ Ref_{L}\langle BH_{L},EH_{L}\rangle\\ ES_{sp|pat}EP_{Ksp}|PK_{pat}(S_{data})\end{array}  \tag{3}\]  
A patient may have multiple inventories from different healthcare providers (i.e., different \(S_{data}\)). In addition, a provider can divide the inventory of a patient into multiple inventories, e.g., according to the hospital departments, which provides more flexibility in inventory storage and management. **Session**. A session describes a data sharing between a patient and a third party, e.g., a doctor, called a requester. Def. (4) shows the session definition. It includes a session ID (\(SID\)) and multiple sections. Session ID is the event hash of the corresponding session creation event in the blockchain. A session contains the directory of all the shared data, but it divides them into multiple sections according to patient inventories to facilitate management. Actually, each section contains some of the entries copied from the corresponding inventory (after decryption by \(S_{data}\)). Thus, the section ID is the _InvID_ of the inventory. Each entry of a section is composed of the _DID_, the metadata, the URL of the actual data, and the reference (_Ref_ or _Ref_\({}_{L}\)) to the _Event\({}_{DG}\)_ in the blockchain. For the data stream, the range of data allowed to access can also be specified (i.e., by _st_ and _et_). In this case, _Ref_\({}_{L}\) refers to the last shared chunk. For privacy, the entries of a section are encrypted by the section secret \(K_{sec}\). \(K_{sec}\) is shared to the requester for accessing the shared data. It is also shared with the corresponding healthcare provider for metadata and URL update and data access verification. To securely distribute the section secret, \(K_{sec}\) is encrypted with the public key of the section participants to \(EK_{sp}\), \(EK_{req}\), and \(EK_{pat}\). Notably, different sections and sessions are encrypted with different \(K_{sec}\). \[Session\langle SID,\{Section\}\rangle\] \[Section\langle SectionID,\{Section\}\rangle\] \[SIDSCEvent.EventHash\] \[SectionIDInvID \tag{4}\] \[Section\langle E_{K_{soc}}(\{Entry\}),EK_{sp},EK_{req},EK_{pat}\rangle\] \[Entry\langle DID,\ Metadata,URL(,st,et),Ref_{L}\rangle\] \[Ref_{L}\langle BH,EH\rangle|\langle BH_{L},EH_{L}\rangle\] \[EK_{sp|pat}|EP_{PK_{sp}|PK_{req}|PK_{pat}}(K_{soc})\]  
Besides the blockchain service, super peers are also connected to provide the directory service.