Skip to content

Commit

Permalink
asset adding api added
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed May 27, 2018
1 parent abece1f commit 9eae399
Show file tree
Hide file tree
Showing 33 changed files with 4,444 additions and 4,168 deletions.
Binary file modified healthchain/admin@healthchain.card
Binary file not shown.
Binary file added healthchain/healthchain@0.0.4.bna
Binary file not shown.
Binary file removed healthchain/himanshu2@healthchain.card
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions healthchain/index.js
Expand Up @@ -3,7 +3,7 @@ var http = require('http').Server(app);
var io = require('socket.io')(http);
var ipfs = require('./modules/ipf/upload');


var addAssets = require('./modules/participants/addAssets');
var fileUpload = require('express-fileupload');
var identity = require('./modules/auth/register')
var auth = require('./modules/auth/authenticate');
Expand All @@ -24,7 +24,7 @@ app.use('/auth',auth);
app.use('/identity',identity);
app.use('/get',getParticipant);


app.use('/assets',addAssets);
app.get('/', (req,res)=>{
res.send('hello world');
})
Expand Down
16 changes: 13 additions & 3 deletions healthchain/modules/auth/authenticate.js
Expand Up @@ -4,17 +4,26 @@ var router = express.Router();
var fs = require('fs');
//for linux

//var card = fs.readFileSync('/home/himanshu/healthchain/healthchain/admin@healthchain.card');




router.post('/login',(req,res)=>{

let card = req.files.card.data;

myNetwork.importCardFromNetwork(card).then((cardName)=>{
if (!req.files)
{
return res.status(400).send('No files were uploaded.');
}

console.log('adminCard' + card);


if(cardName){
res.json({
accessToken : cardName,
cardName: cardName
cardname: cardName
});
}
else {
Expand All @@ -26,6 +35,7 @@ router.post('/login',(req,res)=>{
})




})

Expand Down
2 changes: 1 addition & 1 deletion healthchain/modules/auth/myNetwork.js
Expand Up @@ -47,7 +47,7 @@ class MyNetwork {
}
})
.then((businessDefinition)=>{
console.log(businessDefinition)

if(!businessDefinition){
console.log("not defined");
return null;
Expand Down
13 changes: 9 additions & 4 deletions healthchain/modules/auth/register.js
Expand Up @@ -10,7 +10,7 @@ var fs = require('fs');
//for windows
var Create = require('./../../node_modules/composer-cli/lib/cmds/card/lib/create.js')
var express = require('express');

var adminCard = fs.readFileSync('/home/himanshu/healthchain/healthchain/admin@healthchain.card');
var router = express.Router();
//require req body fields:-
////userType is type of participant ,Patient | Practitioner
Expand All @@ -33,7 +33,7 @@ router.post('/register',async (req,res)=> {
let participant = factory.newResource('org.mpr.healthchain.participant', 'Patient', req.body.participantId);
participant.authPractitioners = [];
participant.records= [];
participant.publicKey = req.body.publicKey;

await participantRegistry.add(participant);
console.log("sucess patient");

Expand All @@ -46,8 +46,12 @@ router.post('/register',async (req,res)=> {
console.log(`userID = ${result.userID}`);
console.log(`userSecret = ${result.userSecret}`);
var exp = await adminConnection.exportCard('admin@healthchain');

var bNetwork = exp.metadata.businessNetwork;
console.log(exp)
console.log("himanshu"+bNetwork)
var connPro= exp.connectionProfile;
console.log(JSON.stringify(exp.connectionProfile));
options.participantId = req.body.participantId;
options.issuer = false;
options.newUserId = result.userID;
Expand All @@ -72,6 +76,7 @@ router.post('/register',async (req,res)=> {
var file = fs.readFileSync(fileName);

console.log(file)
console.log(file.toString('utf8'))
console.log(req.body.participantId);
console.log(req.body.userType);
console.log(req.body.userId);
Expand Down Expand Up @@ -104,7 +109,7 @@ router.post('/register',async (req,res)=> {
let factory = businessNetworkConnection.getBusinessNetwork().getFactory();
let participant = factory.newResource('org.mpr.healthchain.participant', 'Practitioner', req.body.participantId);
participant.patients = [];
participant.publicKey = req.body.publicKey;
participant.publicKey = '90493039409';
participant.accessKeys = [];

await participantRegistry.add(participant);
Expand All @@ -124,7 +129,7 @@ router.post('/register',async (req,res)=> {
options.participantId = req.body.participantId;
options.issuer = false;
options.newUserId = result.userID;
options.card = 'admin@healthchain'
options.card = adminCard
let metadata = {
userName : result.userID,
version: 1,
Expand Down
12 changes: 0 additions & 12 deletions healthchain/modules/ipf/upload.js
Expand Up @@ -3,18 +3,6 @@ var multer = require('multer');
var router = express.Router();
var uploadDoc = require('./ipfs')

const cpUpload = multer({
// multer settings
limits: { fileSize:20*1024*1024 },
//storage: storage,
fileFilter: function (req, file, cb) {
if (file.mimetype !== 'application/pdf' && file.mimetype !== 'image/jpeg' && file.mimetype !== 'image/jpe' && file.mimetype !== 'image/jpg') {
req.fileValidationError = 'goes wrong on the mimetype';
return cb(null, false);
}
cb(null, true);
}
}).single('ipfs');

router.post('/upload',uploadDoc);
router.get('/',(req,res)=>{
Expand Down
30 changes: 30 additions & 0 deletions healthchain/modules/participants/addAssets.js
@@ -0,0 +1,30 @@
var express = require('express');
var router = express.Router();

var BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;

router.post('/adddoctor',async (req,res)=>{
let businessNetworkConnection = new BusinessNetworkConnection();
try {
await businessNetworkConnection.connect('himanshuchawla@healthchain');
//adding user to registry
let assetRegistry = await businessNetworkConnection.getAssetRegistry('org.mpr.healthchain.personalDetails.PractitionerDetails');
let factory = businessNetworkConnection.getBusinessNetwork().getFactory();
let asset = factory.newResource('org.mpr.healthchain.personalDetails', 'PractitionerDetails', 'himanshuchawla@healthchain');
let prac = factory.newRelationship('org.mpr.healthchain.participant','Practitioner','00921202015');
asset.firstname = 'himanshu'
asset.lastname = 'chawla'
asset.email ='himanshuchawla2014@gmail.com'
asset.dob = '30/may/1997'
asset.practitioner= prac;
await assetRegistry.add(asset);
console.log("sucess doctor");

}
catch(error) {
console.log(error + "error occured");
process.exit(1);
}
})

module.exports = router;
1 change: 1 addition & 0 deletions healthchain/modules/participants/queryParticipant.js
Expand Up @@ -22,6 +22,7 @@ router.post('/patients',async ()=> {
process.exit(1);
}
})

router.post('/doctors',async ()=> {
let businessNetworkConnection = new BusinessNetworkConnection();

Expand Down

0 comments on commit 9eae399

Please sign in to comment.