# MedicalRecord **Repository Path**: ghcc/MedicalRecord ## Basic Information - **Project Name**: MedicalRecord - **Description**: 基于区块链的电子病历管理系统 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2020-04-30 - **Last Updated**: 2021-11-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 基于区块链的电子病历管理系统 ## 一、涉及技术 Fabric、SpringBoot、Thymeleaf、Bootstrap、Ajax、JSON、Lombok ## 二、环境说明 -[x] Ubuntu16.04 64位 [需要安装Fabric单机环境](https://blog.csdn.net/qq_36254699/article/details/104459108) -[x] Fabric1.4.0 -[x] SpringBoot2.0.6 -[x] JDK1.8 -[x] Thymeleaf3.0.9.RELEASE -[x] Bootstrap4.0.0 ## 三、登录入口 ### 系统管理员 -[x] 注册 http://localhost:8099/MedicalRecord/user/registerView -[x] 管理链码 http://localhost:8099/MedicalRecord/user/uploadChaincodeView ### 普通用户 -[x] 登录 ## 四、源码地址 ### GO语言合约开发 git https://gitee.com/hbuzzs/MedicalRecordChainCode ### Fabric SDK git https://gitee.com/hbuzzs/FabricSDK.git ### Java SpringBoot+BootStrap档案管理 git https://gitee.com/hbuzzs/MedicalRecord ## 五、keyValue存储设计 ### 5.1 查询每个合约的所有记录 key:合约名字 value:对应合约每条记录的的ID ### 5.2 查询用户授权的档案情况 key:档案所属人ID value:档案ID ## 六、命令行安装区块链 ### 1. 智能合约目前版本 ``` ComplaintInfo 1.1 KeyTransaction 1.0 KeyValue 1.0 PatientRecord 1.1 RecordBillTransaction 1.0 UserInfo 1.0 UserStoreTranInfo 1.0 Wallet 1.0 ``` ### 2. 查看已安装合约 ```$xslt peer chaincode list --installed ``` ### 3. 实例化合约代码(只需要在一个节点实例化就可以) ``` peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n complaintInfo -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n keyTransaction -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n patientRecord -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n recordBillTransaction -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n userStoreTranInfo -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n userInfo -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n keyValue -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" ``` ### 4. 查看已实例化的合约 ```$xslt peer chaincode list --instantiated -C mychannel ``` ### 5. 触发合约 ``` peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n keyValue --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt -c '{"Args":["save","test","{\"key\":\"userStoreTranInfo\",\"valueA\":\"3\",\"valueB\":\"null\"}"]}' ``` ### 6. 查询合约 ``` peer chaincode query -C mychannel -n recordBillTransaction -c '{"Args":["queryHistory","1"]}' ``` ### 7. 升级合约 ```$xslt peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n recordBillTransaction -v 1.2 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" ``` ## 七、部署Fabric的坑 ### 1. 提示无法加入区块 原因: 华为云服务器的bug 解决:修改/etc/resolv.conf 注释option一行 ### 2. 查询历史记录为空,但是查询最新记录可以显示 云因:GO开发智能合约 因为要处理成json所以GO结构体字段名必须大写 解决:定义结构体变量这样定义:``` ValueA string `json:"valueA"` ```