# A Blockchain-Based Secure Inter-Hospital EMR Sharing System
## 3 The Proposed Scheme
### Inter-Hospital Authentication and Communication Phase  
When the patient carries his/her mobile device and visits hospital B for extended treatment of a symptom that was previously diagnosed in hospital A, hospital B and the patient will also verify one another's identity first. After mutual authentication between the patient and hospital B, the doctor of hospital B obtains the medical index of hospital A from the personal mobile device of the patient. Then, the doctor of hospital B requests the medical records of the patient from hospital A. After the doctor of hospital B obtains the encrypted medical records from hospital A and performs a diagnosis, the doctor of hospital B stores the medical records of the patient in the server of hospital B. The doctor of hospital B also informs the patient about the results. The patient keeps the diagnostic results and medical index in his/her mobile device. The inter-hospital authentication and communication phase of the proposed scheme is shown in Figure 6.  
Figure 6: The inter-hospital authentication and communication phase of the proposed scheme. * The patient chooses a random number, \(c\), calculated by \[T_{PAT2}=cP,\] (34) and then sends \((ID_{PAT},R_{PAT},T_{PAT2})\) to hospital B. * Hospital B chooses a random number, \(d\), calculated by \[T_{HPB}=dP,\] (35) \[PK_{PAT}=R_{PAT}+H_{1}(ID_{PAT},R_{PAT})PK,\] (36) \[K_{BP1}=S_{HPB}T_{PAT2}+dPK_{PAT},\] (37) \[K_{BP2}=dT_{PAT2},\] (38) and the session key, \[SEK_{BP}=H_{2}(K_{BP1},K_{BP2}).\] (39) Hospital B then calculates \[CHK_{PB}=H_{3}(SEK_{BP},T_{PAT2}),\] (40) and sends \((ID_{HPB},R_{HPB},T_{HPB},CHK_{PB})\) to the patient. * The patient calculates \[PK_{HPB}=R_{HPB}+H_{1}(ID_{HPB},R_{HPB})PK,\] (41) Figure 6:0 (42) Figure 6:1 (43) and the session key, Figure 6:2 (44) The patient then verifies Figure 6:3 (45) to check the legality of hospital B. If the verification passes, the patient calls the smart contract hbchk as follows: \ \begin{tabular}{|c||c||c|} \hline function hospital B check smart contract hbchk( & \multirow{2}{*}{
\begin{tabular}{c} return hospital B id. exist; \\ return hospital B detail. exist; \\ \end{tabular} } \\ string hospital B detail) \{ & \(\}\) \\ \hline \end{tabular}  The patient then calculates \[c_{PAT2}=E_{SEK_{BP}}(message)\] (46) \[CHK_{BP}=H_{3}(SEK_{BP},T_{HPB})\] (47) and sends \((ID_{PAT},c_{PAT2},CHK_{BP})\) to hospital B. * Hospital B verifies \[CHK_{BP}\stackrel{{?}}{{=}}H_{3}(SEK_{BP},T_{HPB}),\] (48)  
\[c_{HPB}=E_{SEK_{AB}}(message) \tag{62}\]  
\[CHK_{AB}=H_{3}(SEK_{AB},T_{HPA2}) \tag{63}\]  
and sends \((ID_{HPB},c_{HPB},CHK_{AB})\) to hospital A. * Hospital A verifies \[CHK_{AB}\stackrel{{?}}{{=}}H_{3}(SEK_{AB},T_{HPA2})\] (64)  
to check the legality of hospital B. If the verification is passed, the session key \(SEK_{AB}\) between hospital B and hospital A is established successfully. Hospital A then decrypts the received message  
\[message=D_{SEK_{AB}}(c_{HPB}) \tag{65}\]  
and receives the medical record request from the patient. Hospital A then generates the encrypted medical records of the patient  
\[c_{HPA2}=E_{SEK_{AB}}(EMR), \tag{66}\]  
\[Sig_{HPA2}=S_{SK_{HPA}}(EMR), \tag{67}\]  
and sends \((ID_{HPA},c_{HPA2},Sig_{HPA2})\) to hospital B. * Hospital B decrypts the received message \[EMR=D_{SEK_{AB}}(c_{HPA2}),\] (68) verifies the signature, \[CHK_{BP}=H_{3}(SEK_{BP},T_{HPB})\]0 (69)  
If the verification passes, and hospital B calls the smart contract mrchk as follows: \begin{tabular}{|p{142.3 pt}||p{142.3 pt}|} \hline string diagnosis id, & verify string hospital A key ( \\ string diagnosis detail) \{ & hospital A information, \\ return diagnosis id. exist; & patient information); \\ return diagnosis detail. exist; & function medical record check smart contract mrchk( \\ \} \\ \} & \\ \hline \end{tabular}   
Hospital B then receives the encrypted medical records of the patient from hospital A.